尝试确定特定的数据库规范化问题
一位同事将新表的值勾勒如下:
"Foo", "some value 1"
"Foo", "some value 2"
"Foo", "some value 3"
"Bar", "some value 3"
这些是表中唯一的列。 列名称为 Col1、Col2。
一个人说这张表没有标准化,另一个人说是。
违反规范化的具体论点是,删除 Col1“Foo”中带有“Foo”的三个记录将不再出现在系统中。 那个人说应该有一个包含 ID 和名称列的查找表。 上表将引用该表的 Id 作为其 FK。
认为它没有标准化的论点是表中没有依赖于第一列(第三标准化形式)的第三列。
我认为混乱来自于它是 1NF,因为它满足这个例子:
Customer Tr. ID Date Amount
Jones 12890 14-Oct-2003 -87
Jones 12904 15-Oct-2003 -50
Wilkins 12898 14-Oct-2003 -21
Stevens 12907 15-Oct-2003 -18
Stevens 14920 20-Nov-2003 -70
Stevens 15003 27-Nov-2003 -60
来自 http://en.wikipedia .org/wiki/Database_normalization。
但听起来它违反了这个规则,“相同的信息可以在多行上表达;因此对表的更新可能会导致逻辑不一致。” 这适用于超过 1NF 的归一化。
所以看起来原始表会违反 2NF,从而违反 3NF,但会满足 1NF。 它是否正确?
A coworker sketched out the values of a new table as:
"Foo", "some value 1"
"Foo", "some value 2"
"Foo", "some value 3"
"Bar", "some value 3"
These are the only columns in the table. The column names are Col1, Col2.
One person said that this table is not normalized, another said it is.
The specific argument that it violated normalization is that removing the three records with "Foo" in Col1 "Foo" would no longer be present in the system. That person said there should be a lookup table containing an ID, and Name column. The table above would reference the Id of that table as its FK.
The argument that it wasn't normalized is that there wasn't a third column in the table dependent on the first (3rd normalized form).
The confusion I think comes from it being 1NF in that it satisfies this example:
Customer Tr. ID Date Amount
Jones 12890 14-Oct-2003 -87
Jones 12904 15-Oct-2003 -50
Wilkins 12898 14-Oct-2003 -21
Stevens 12907 15-Oct-2003 -18
Stevens 14920 20-Nov-2003 -70
Stevens 15003 27-Nov-2003 -60
from http://en.wikipedia.org/wiki/Database_normalization.
But it sounds like it violates this rule, "The same information can be expressed on multiple rows; therefore updates to the table may result in logical inconsistencies." This applies to normalization beyond 1NF.
So it looks like the original table would violate 2NF, and thereby 3NF, but would satisfy 1NF. Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果这两列真的全部存在,那么我会说这个数据库表是第三范式。 这是我的推理:
我不知道你的工作伙伴是否想真正进入 4NF、5NF 或 Boyce-Codd NF - 我非常怀疑……
Marc
If those two columns are really all there are, then I would say this database table is in third normal form. Here's my reasoning:
I don't know if your work buddy wants to really get into 4NF, 5NF or Boyce-Codd NF - I highly doubt it......
Marc
有不同的标准化级别。 但如果没有实际的字段名称,您就无法真正知道是否需要标准化。
There are different normalization levels. But without the actual field names, you can't really know if you need to normalize.
http://en.wikipedia.org/wiki/Database_normalization
http://en.wikipedia.org/wiki/Database_normalization
有一些不同级别的标准化。
如果“Foo”,“某个值1”“Foo”,“某个值2”“Foo”,“某个值3”“Bar”,“某个值3”
意味着该表看起来像:
Col1/Col2 上有一个主键,那么是的,它是“标准化”的。
如果根本没有键,那么不,它没有标准化,因为您可以插入“Bar”的另一个实例“some value 3”。
关于您添加的新问题:
如果存在跨越 Col1 和 Col1 的 PK, Col2,那么它仍然处于2NF和3NF。 您必须添加一个不属于违反任一键的列,然后它必须只能从 Col1 或只能从 Col2 派生。
There are a few different levels of normalization.
If "Foo", "some value 1" "Foo", "some value 2" "Foo", "some value 3" "Bar", "some value 3"
means that the table would look like:
And there is a primary key on Col1/Col2 then yes, it is 'Normalized'.
If there is no key at all, then no, it is not normalized, as you could insert another instance of "Bar", "some value 3".
As to the new question you added:
If there is a PK spanning Col1 & Col2, then it is still in 2NF and 3NF. You'd have to add a column that is not a part of the key to violate either, and then it would have to be derivable from only Col1 or only Col2.
我相信表中的值列表代表四行:
根据我的理解,该表将被视为标准化。 我希望这里的主键是 {col1, col2} 的组合键。
当 col1 和 col2 分别是包含所映射实体的附加属性的其他表的外键时,我通常希望在表中看到这种类型的多对多值映射。
我还建议考虑数字键而不是这些 nvarchar 值。 我怀疑这些文本值可能不是它们所代表的实体的良好候选键,但我没有足够的信息来完全做出该判断。
I believe the list of values in the table represent four rows:
Based on my understanding, this table would be considered normalized. I would expect the primary key here to be a composite key of {col1, col2}.
I would normally expect to see this type of many-to-many mapping of values in a table when col1 and col2 are each foreign keys into other tables that contain additional attributes of the entities being mapped.
I would also recommend considering numeric keys rather than these nvarchar values. I suspect that these textual values may not be good candidate keys for the entities they represent, but I don't have enough information to fully make that judgment.