null value in foreign key

Ziyang Zhang picture Ziyang Zhang · Jun 4, 2012 · Viewed 7.7k times · Source

I copied the following paragraph from http://msdn.microsoft.com/en-us/library/ms175464(v=sql.105).aspx

A FOREIGN KEY constraint can contain null values; however, if any column of a composite FOREIGN KEY constraint contains null values, verification of all values that make up the FOREIGN KEY constraint is skipped. To make sure that all values of a composite FOREIGN KEY constraint are verified, specify NOT NULL on all the participating columns.

Could someone provide me with a simple example to help me understand the above? What verification the foreign key constraint will do? I think this has something to do with referential integrity.

Thanks a lot.

Answer

Tony picture Tony · Jun 4, 2012

You shouldn't need an example if you think of it in another way.

If any of the fields in a composite foreign key are NULL then none of the other fields are checked for integrity until all fields of the key are provided.