INF:Foreign Key Constraint Behavior of Nullable Composite Keys (153370)
The information in this article applies to:
- Microsoft SQL Server 6.0
- Microsoft SQL Server 6.5
This article was previously published under Q153370 SUMMARY
A foreign key constraint may be satisfied under some conditions which may
seem unexpected or unusual. Specifically, if a composite foreign key has
been defined on columns that allow nulls, and at least one of the columns,
upon the insert or update of a row, is set to null, then the foreign key
constraint will be satisfied. This is true even if there is not a row in
the related table to which any of the corresponding columns are matched.
Consider the following example involving tables t1 and t2, defined as
follows:
t1: (col1, col2)
primary key (col1,col2)
t2: (col1 null, col2 null)
foreign key (col1,col2) references t1
If t1 contains one row:
col1 col2
---- ----
A 2
The foreign key constraint on t2 can be met by the statement "insert into
t2 values('B',null)."
Modification Type: | Major | Last Reviewed: | 10/16/2003 |
---|
Keywords: | KB153370 |
---|
|