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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Foreign key doubt

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-04-15 : 00:49:15
hi al,
We normally use foreign key in a table, as a reference to a primary key in another table.
But by definition foreign key can assume null value.so my question is when we are using foreign key as null in a table.Clarification with an example would be great..
thanks in advance..

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-04-15 : 04:00:09
A FK does not allow null 'by definition', it is just that sometimes it is optional (or the developer is lazy). Create/alter your table with NOT NULL on the FK if your data model does not allow it.
Examples of legitimate nullable FKs include managerID on an employee table where the employee might not have a manger or a countryID on a table where you record an optional country from a predefined set.
Go to Top of Page
   

- Advertisement -