外键如何具有空值,而主键不能有? [英] How foreign key can have null values where as primary key can't have?
本文介绍了外键如何具有空值,而主键不能有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很惊讶外键可以在sql server中引用其引用表上的空值。如果有人用简单的例子向我解释,我会很感激。
谢谢
I am surprise of that foreign key can refer to null value on its reference table in sql server.I would appreciate if someone explain this to me with simple example.
Thank you
推荐答案
为什么他们不应该有null
值?主键不能,因为null
不是唯一值 - 这是主键 [ ^ ]。 外键 [ ^ ]只是将一个表中的一行与另一个表中的唯一行相关联,因此当没有时,null
这样的行存在。
Why shouldn't they havenull
values? Primary keys can't becausenull
is not a unique value - which is a requirement of a Primary key[^]. A Foreign key[^] just relates a row in one table to a unique row in another table, and so can benull
when no such row exists.
这篇关于外键如何具有空值,而主键不能有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文