如果更改主键值,为什么不必须更改从属列值? [英] If we change a primary key value, why don't we have to change a dependent column value?

查看:66
本文介绍了如果更改主键值,为什么不必须更改从属列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观看了 YouTube上的一个有关数据库规范化的教程./p>

该表如下所示:

  | Item(PK)|供应商|供应商电话|价格|---------------------------------------------|Xbox One |微软|1234 |250 |---------------------------------------------|PS4 |索尼|4321 |300 |---------------------------------------------|PS Vista |索尼|4321 |400 |--------------------------------------------- 

根据教程,该表以2NF表示,每列取决于PK.

我不明白的是供应商列如何依赖于PK,并且对于不同的行具有相同的值.如果逻辑是B(供应商)取决于A(PK),而我们改变了A,那么是否应该改变B?为什么在这种情况下更改后的PK的供应商会保持不变?

解决方案

TL; DR Item/A为PK(主键)意味着每个Item/A值只有一个Supplier/B值.并不是说每个表只有一个值.

该视频是胡说八道.他们也对依赖"和误解"有同样的误解.FD(功能相关性)&PK作为您的问题(也许就是您从中获取PK)和许多其他误解的原因,他们不知道自己在说什么.查找大学/大学的教科书,幻灯片和/或课程(其中许多都是在线免费提供的).


我们可以讨论FD,超级键,唯一列集,CK(候选键)和表 value 或表变量的PK.如果在给定业务/应用程序中可能出现的每个表值都将其作为实例,则表变量具有其中之一的实例.

我不了解的是供应商列如何依赖于PK,并且对于不同的行具有相同的值.

当确定的集合的每个给定值仅具有一个值时,列集合在功能上将依赖于另一列.

但这并不意味着不同的确定值具有不同的确定值.

超键是一组列,每行中都有不同的子行值.CK是不包含较小超级键的超级键.PK是您选择作为PK的某些CK.每个列在功能上取决于每个超级键.其中一些是CK.其中之一可以是PK.

但是,这并不意味着除超键/CK/PK之外的某些子行其他(并且每个子行必须在功能上都依赖于根据定义).

如果逻辑上说B(供应商)取决于A(PK),而我们改变了A,那么是否应该改变B?

不是基于A为PK/CK.存在PK/CK表示A和A的每个超集都是唯一的.如果您在查看其他行"或查看具有不同A值的表值(不能在任一表的任何其他行中)的意义上更改A",则不会限制B可以是什么.

某些 other 约束可能会限制B可以是什么.例如,如果FD {供应商}-> {供应商电话}成立,那么这将限制其他行中的供应商电话可以显示,即使ItemPK不能.

在给定情况下,是否有任何特定的FD保留取决于应将哪些行放入表中?会发生什么情况.然后,FD持有什么来确定什么是超键& ;?CKs.然后,您可以选择一个CK作为PK.

I watched one tutorial on youtube about database normalization.

The table looks like this:

|Item(PK) | Supplier | Supplier Phone | Price|
---------------------------------------------
| Xbox One| Microsoft| 1234           | 250  |
---------------------------------------------
| PS4     | Sony     | 4321           | 300  |
---------------------------------------------
| PS Vista| Sony     | 4321           | 400  | 
---------------------------------------------

According to the tutorial this table is in 2NF and every column depends on the PK.

What I don't understand is how column Supplier depends on the PK and has the same value for different rows. If the logic is that B (supplier) depends on A (PK), and we change A, should B be changed? Why in this case would the Supplier for the changed PK remain the same?

解决方案

TL;DR Item/A being PK (primary key) implies that there's only one Supplier/B value per Item/A value. It doesn't say that there's only one value per table.

That video is nonsense. They are suffering from the same misconceptions about "depends" & FDs (functional dependencies) & PKs as your question (so maybe that's where you got them from) and many other misconceptions and they don't know what they are talking about. Find an college/university textbook, slides and/or course (of which many are free online).


We can talk about the FDs, superkeys, unique column sets, CKs (candidate keys) & PK of a table value or a table variable. A table variable has an instance of one of those things if every table value that can arise in the given business/application has it as an instance.

What I don't understand is how column Supplier depends on PK and has the same value for different rows.

A column set is functionally dependent on another when the determined set can only have one value per given value of the determining set.

But that doesn't imply that different determining values have different determined values.

A superkey is a set of columns that has a different subrow value in every row. A CK is superkey containing no smaller superkey. A PK is some CK that you chose to be PK. Every column set functionally depends on every superkey. Some of which are CKs. One of which can be PK.

But that doesn't imply that some subrow other than a superkey/CK/PK (and every subrow must be functionally dependent on them by definition) is unique.

If the logic is that B (supplier) depends on A (PK), and we change A, should B be changed?

Not on the basis of A being PK/CK. A being PK/CK implies that A and every superset of A is unique. If you "change A" in the sense of looking at a different row or looking at a different table value that has a different A value for that row (which can't be in any other row of either table), that doesn't restrict what B can be.

Some other constraint might restrict what B can be. Eg if the FD {Supplier} -> {Supplier Phone} holds then that restricts what Supplier Phone can be in other rows even though Item being PK does not.

Whether any particular FD holds depends on what rows are supposed to go into a table in a given situation & what situations can arise. Then what FDs hold determines what the superkeys & CKs are. Then you can pick a CK as PK.

这篇关于如果更改主键值,为什么不必须更改从属列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆