Re: foreign constraint with unique key

From: David Portas <>
Date: Tue, 3 Feb 2009 22:40:50 -0000
Message-ID: <>

"Norbert Winkler" <> wrote in message
> Hi,
> I've tried to create a foreign key on two columns, where the second col
> should be nullable to avoid a trigger for testing integrity.

A foreign key that includes a nullable column does not compare nulls between the two tables. Instead a multi-column constraint will never be violated on a row that contains a null - even if the value(s) in the other column(s) are not present in the referenced table. Nullable foreign keys are pretty useless in most cases.

I suggest you do without a nullable foreign key. Have one table with the constraint on one column and another with the constraint on two.

David Portas
Received on Tue Feb 03 2009 - 16:40:50 CST

Original text of this message