Jeff Smith Blog

Random Thoughts & Cartesian Products with Microsoft SQL Server

SQL Server 2005 Foreign Key Constraints: SET NULL and SET DEFAULT

Most people know about cascading updates and deletes, but did you know there are two other foreign key constraint options you can use to maintain referential integrity?

Read all about them in my latest article over at SQLTeam.com.

These features, introduced with SQL Server 2005, haven't got a lot of publicity, but they can be very useful.  I just used the SET NULL option recently for the first time (inspiring me to put together an article on it) and it works great.

Legacy Comments


nilesh
2008-09-26
re: SQL Server 2005 Foreign Key Constraints: SET NULL and SET DEFAULT
fine thanks

seenu
2008-12-13
re: SQL Server 2005 Foreign Key Constraints: SET NULL and SET DEFAULT

I'm loading a dataset from a cached viewstate version of the dataset
created

"Failed to enable constraints. One or more rows contain values violating
non-null, unique, or foreign-key constraints"
I suspect this is due to a field in one of the tables which can be null,
but
if it is not null it is a foreign key to another dataset table. At
present
the field in this table is null (in the database).

What attributes of the dataset table field, or the dataset constraint
should
I set to indicate null values don't violate the constraint?

by
seemu

DBA
2009-01-23
re: SQL Server 2005 Foreign Key Constraints: SET NULL and SET DEFAULT
Really. I did not know about this until now...
Anyway I don't think we should use cascades in regard of integrity.
thanks, Vadym