Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 can a foreign key contain nulls?

Author  Topic 

archanasql
Starting Member

27 Posts

Posted - 2008-02-08 : 13:55:37
Hi,

Can a foreing key ever contain null values and if so how many null values can it contain? and how can a foreign key contain null values when we have a referential integrity in referenced table with the Primary key which cannot contain null values? i am totally confused..? Please clarify?

hali14
Starting Member

5 Posts

Posted - 2008-02-08 : 14:02:14
No
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-08 : 14:04:30
A foreign key constraint exists only to prevent values that don't exist in the <foreign> table. The nullability property of the column determines if nulls are allowed. So a Nullable column that references another table.column can contain unlimited nulls. On the other hand if you want to insure that every row is accounted for (no nulls) then make the column NOT NULL.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -