尝试确定特定的数据库规范化问题

发布于 2024-07-24 06:06:03 字数 982 浏览 6 评论 0原文

一位同事将新表的值勾勒如下:

"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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

萌︼了一个春 2024-07-31 06:06:03

如果这两列真的全部存在,那么我会说这个数据库表是第三范式。 这是我的推理:

  1. 显然在 1NF 中,因为没有一个属性是“多值”的,
  2. 因为 col1 和 col2 都不是有效的候选键(重复值!),唯一可能且有效的主键该表是 (col1,col2)
  3. 2NF 规定任何非素数属性在功能上都不应依赖于候选键的一部分。 由于只有 col1 和 col2 都是唯一可能的候选键的一部分,因此这一点没有实际意义 -
  4. 根据 EFCodd 的 2NF 3NF 中的表 IS 基本上表明任何非键属性都必须依赖“在钥匙上,整个钥匙,除了钥匙什么都没有”。 由于我们只有有两列构成键,因此没有其他非键属性,因此没有一个非键属性违反此规则 --> 表 IS 是 3NF

我不知道你的工作伙伴是否想真正进入 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:

  1. It's CLEARLY in 1NF since none of the attributes are "multi-valued"
  2. Since neither col1 nor col2 are a valid key candidate (duplicate values!), the only possible and valid primary key on this table is (col1,col2)
  3. 2NF stipulates that no non-prime attribute shall be functionally dependent on a part of a candidate key. Since there are only col1 and col2 which are both part of the only possible candidate key, this point is moot - the table IS in 2NF
  4. 3NF according to E.F.Codd basically says that any non-key attribute must be dependent "on the key, the whole key, and nothing but the key". Since we ONLY have two columns which make up the key, there are no other non-key attributes, so none of the non-key attributes violates this rule --> the table IS is 3NF

I don't know if your work buddy wants to really get into 4NF, 5NF or Boyce-Codd NF - I highly doubt it......

Marc

生死何惧 2024-07-31 06:06:03

有不同的标准化级别。 但如果没有实际的字段名称,您就无法真正知道是否需要标准化。

There are different normalization levels. But without the actual field names, you can't really know if you need to normalize.

年少掌心 2024-07-31 06:06:03

有一些不同级别的标准化

如果“Foo”,“某个值1”“Foo”,“某个值2”“Foo”,“某个值3”“Bar”,“某个值3”
意味着该表看起来像:

Col1| Col2
------------------
Foo | some value 1
Foo | some value 2
Foo | some value 3
Bar | some value 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:

Col1| Col2
------------------
Foo | some value 1
Foo | some value 2
Foo | some value 3
Bar | some value 3

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.

北方的韩爷 2024-07-31 06:06:03

我相信表中的值列表代表四行:

col1 col2
Foo  some value 1
Foo  some value 2
Foo  some value 3 
Bar  some value 3

根据我的理解,该表将被视为标准化。 我希望这里的主键是 {col1, col2} 的组合键。

当 col1 和 col2 分别是包含所映射实体的附加属性的其他表的外键时,我通常希望在表中看到这种类型的多对多值映射。

我还建议考虑数字键而不是这些 nvarchar 值。 我怀疑这些文本值可能不是它们所代表的实体的良好候选键,但我没有足够的信息来完全做出该判断。

I believe the list of values in the table represent four rows:

col1 col2
Foo  some value 1
Foo  some value 2
Foo  some value 3 
Bar  some value 3

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文