数据库----数据库规范化
有人告诉我下表不适合第二次数据库规范化。但我不知道为什么?我是数据库设计的新手,我读过一些3NF的教程。但对于2NF和3NF,我不能很好地理解它们。期待有人能为我解释一下。谢谢你,
+------------+-----------+-------------------+
pk pk row
+------------+-----------+-------------------+
A B C
+------------+-----------+-------------------+
A D C
+------------+-----------+-------------------+
A E C
+------------+-----------+-------------------+
someone told me the following table isn't fit for the second database normalization. but i don't know why? i am a newbie of database design, i have read some tutorials of the 3NF. but to the 2NF and 3NF, i can't understand them well. expect someone can explain it for me. thank you,
+------------+-----------+-------------------+
pk pk row
+------------+-----------+-------------------+
A B C
+------------+-----------+-------------------+
A D C
+------------+-----------+-------------------+
A E C
+------------+-----------+-------------------+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您在此处说明应该满足哪些依赖关系,否则无法正确回答您的问题。您似乎有两个具有相同名称 (pk) 的属性,在这种情况下,该表甚至不满足 1NF,因为它不符合关系。
Your question cannot be answered properly unless you state what dependencies are supposed to be satisfied here. You appear to have two attributes with the same name (pk), in which case this table doesn't even satisfy 1NF because it doesn't qualify as a relation.
关于您的示例:该表不适合第二个数据库规范化(使用您的示例数据,我认为 C 仅依赖于 A)。第二种标准化形式要求:
所以 C 取决于“ A”,它是主键的子集。您的主键是一个特殊的超级键。 (dportas 指出它不能称为候选键,因为它不是最小的)。
让我们更多地了解第二种规范化形式。为了便于理解,稍微改变一下您的示例,假设有一个表
CUSTOMER(customer_id, customer_name, address)
。超级键是唯一确定管的属性的子集。在本例中,有 3 个超级键: (customer_id) ; (客户 ID,客户名称); (客户 ID、客户名称、地址)。 (2 个人的客户名称可能相同)在您的情况下,您已确定 (customer_id, customer_name) 为主键。违反了第二种形式的规则;因为它只需要 customer_id 来唯一确定数据库中的管。 为了理论准确性,这里的问题是由主键(不是候选键)的选择引起的,尽管可以应用相同的论点来显示冗余。您可能会在此处找到一些有用的示例。
第三范式指出:
让我们举个例子。更改前一个表以适应第二种形式,现在我们有表
CUSTOMER(customer_id,customer_name, city, postal_code)
,其中 customer_id 是主键。显然,“postal_code”取决于客户的“城市”。这就是它违反了第三条规则的地方:postal_code取决于city,city取决于customer_id。这意味着 postal_code 传递依赖于 customer_id,因此该表不符合第三范式。
为了纠正它,我们需要消除传递依赖。因此,我们将该表拆分为 2 个表:
CUSTOMER(customer_id, customer_name, city)
和CITY(city, postal_code)
。这可以防止在同一城市和地区拥有太多管道的冗余。邮政编码。About your example: that table doesn't fit the second database normalization (with your sample data, I presume that the C depends only on A). The second normalization form requires that:
So the C depends on "A", which is a subset of your primary key. Your primary key is a special superkey. (dportas point out the fact that it can't be called candidate key, since it's not minimal).
Let's say more about the second normalization form. Transform your example a little for easy understanding, presume that there's a table
CUSTOMER(customer_id, customer_name, address)
. A super key is a sub-set of your properties which uniquely determine a tube. In this case, there are 3 super key: (customer_id) ; (customer_id, customer_name) ; (customer_id, customer_name, address). (Customer name may be the same for 2 people)In your case, you have determined (customer_id, customer_name) be the Primary Key. It violated the second form rules; since it only needs customer_id to determine uniquely a tube in your database. For the sake of theory accuration, the problem here raised from the choice of primary key(it's not a candidate key), though the same argument can be applied to show the redundance. You may find some useful example here.
The third normal form states that:
Let give it an example. Changing the previous table to fit the second form, now we have the table
CUSTOMER(customer_id,customer_name, city, postal_code)
, with customer_id is primary key.Clearly enough, "postal_code" depends on the "city" of customer. This is where it violated the third rule: postal_code depends on city, city depends on customer_id. That means postal_code transitively depends on customer_id, so that table doesn't fit the third normal form.
To correct it, we need to eliminate the transitive dependence. So we split the table into 2 table:
CUSTOMER(customer_id, customer_name, city)
andCITY(city, postal_code)
. This prevent the redundance of having too many tubes with the same city & postal_code.