How to allow null values on foreign keys in MS SQL Server 2012?

Viewed 5215

How to allow null (empty) values on foreign key column in MS SQL Server 2012 and preserve referential integrity? I created constraint on foreign key in child table. It prevents deleting primary key record in parent table and it is OK. But it does not allow me to add (insert) new record into child table, leaving foreign key column empty. I have a lot of those situation in my app, where I would like to have possibility to leave FK column empty, and still have Referential Integrity ON, at least for Deleting from parent table. How to implement that???

3 Answers

null values are not empty values. An empty value may refer to something in another table but a null value cannot refer to anything because it signifies that there is nothing to refer to. So allowing null values will by no means preserve referential integrity.

Related