规范化:单行中的两列需要来自同一个表的数据
我有一个包含以下字段的表:
分配给和完成者
这些字段引用员工表。
我只是想知道这是否正常化或者我是否错过了一些东西。
谢谢
I have a table which has the following fields:
Assignedto and completedby
These fields reference the employee table.
I was just wondering if this is normalized or whether I have missed something.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,将一个表中的多个列作为另一个表的外键是可以的(并且是适当的)。您的案例就是一个很好的例子...
实际上有很多例子 - 客户表可以有一个邮寄地址和一个送货地址,它们都指向一个地址表。联系人表可以有一个家庭电话、工作电话、传真和移动列都指向电话表(尽管还有其他更好的方法来执行此操作)
Yes, it is fine (and appropriate) to have more than one column in a table be a Foreign Key into another table. Your case is a good example of this...
There are lots of examples actually - A Customer Table can have a mailing address and a Delivery address, which both point to an Address table.. A Contact Table could have a HomePhone, WorkPhone, Fax, and Mobile column that all point to a Telephone table (although there are other better ways of doing this one)
注意:我将您的第二个表称为“Stuff”,因为我不知道还能称呼它什么。
如果“AssignedTo”和“CompletedBy”字段都是 Employee 的外键,则为 3NF桌子。如果您确实想要进行规范化,可以使用第三个表 StuffCompletion,它具有标识列和这两个值,并将 Stuff 表中的这两个值替换为 StuffCompletion 的外键。我想大多数人都会认为这太过分了,模式之神可能会给你带来毁灭。
Note: I'll refer to your second table as "Stuff" since I don't know what else to call it.
It's 3NF if the AssignedTo and CompletedBy fields are both foreign keys to the Employee table. If you really want to go nuts with the normalization, you can have a third table, StuffCompletion, that has an identity column and those two values, and replace those two values in your Stuff table with a foreign key to StuffCompletion. I think most people would consider this overkill, and the schema gods may rain destruction upon you.