p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2000 (http://p2p.wrox.com/forumdisplay.php?f=20)
-   -   Foreign Key Problem (http://p2p.wrox.com/showthread.php?t=4324)

re_anu September 26th, 2003 10:13 AM

Foreign Key Problem
I have a general question. Can a Foreign key field take null values? I read at a couple of places that it can , but somme people say that it can't since a FK should be a values referring some PK(makes sense). I am confused. I am designing a database and I need to know soon. Thanks for your help in advance.............

Jeff Mason September 26th, 2003 10:58 AM

A column in a base table which is a foreign key in another table can indeed be null. If there is a referential constraint on the column, then values in that column must be found in the referenced table. But if there is no value in the base column (i.e. NULL), then that is perfectly OK - it doesn't violate the constraint, because NULL means there is no value, so there is nothing to check.

BTW, it is not requirement that the foreign key constraint refer to the primary key of the foreign table, but it usually does. As long as the constraint refers to a column (or columns) which has a UNIQUE constraint defined, the reference will be allowed.

Jeff Mason
Custom Apps, Inc.

All times are GMT -4. The time now is 09:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.