The second. The first is an implementation of the EAV anti-pattern.
To see why the first table is a problem, imagine that we don't know anything about the problem domain. We just know that there are currently two different kinds of floating-point values, labeled GDP and GNP, and that we want to add a third, PWT, and the values of PWT are known to be limited to the range
0.0 < PWT <= 1500.0
Adding that data to the first table is simple. Adding that constraint to the first table, that PWT must be between 0 and 1500, is a different story.
Adding a column to the second table is also simple. And adding a check constraint to guarantee the values are in the right range is both simple and easy.
Imagine that we now want to add a fourth kind of value, one that's limited to dollar amounts > 0. How will you manage a fixed-point value in the first table? But adding that column and its constraint are dead simple in the second table.
发布评论
评论(1)
第二个。第一个是 EAV 反模式的实现。
要了解为什么第一个表是一个问题,请假设我们对问题域一无所知。我们只知道目前有两种不同类型的浮点值,分别标记为 GDP 和 GNP,并且我们想添加第三种浮点值 PWT,已知 PWT 的值限制在
将该数据添加到第一个表中很简单。将约束添加到第一个表中,即 PWT 必须在 0 到 1500 之间,这是一个不同的故事。
向第二个表添加列也很简单。添加检查约束来保证值在正确的范围内既简单又容易。
想象一下,我们现在想要添加第四种价值,一种仅限于美元金额 > 的价值。 0. 您将如何管理第一个表中的定点值?但是在第二个表中添加该列及其约束非常简单。
The second. The first is an implementation of the EAV anti-pattern.
To see why the first table is a problem, imagine that we don't know anything about the problem domain. We just know that there are currently two different kinds of floating-point values, labeled GDP and GNP, and that we want to add a third, PWT, and the values of PWT are known to be limited to the range
Adding that data to the first table is simple. Adding that constraint to the first table, that PWT must be between 0 and 1500, is a different story.
Adding a column to the second table is also simple. And adding a check constraint to guarantee the values are in the right range is both simple and easy.
Imagine that we now want to add a fourth kind of value, one that's limited to dollar amounts > 0. How will you manage a fixed-point value in the first table? But adding that column and its constraint are dead simple in the second table.