Creating a foreign key that references two other tables [message #372572] |
Fri, 23 February 2001 12:40 |
Ken O'Brien
Messages: 3 Registered: February 2001
|
Junior Member |
|
|
Hi ,
I'm fairly new to this and I am trying to create a foreign key based on a composite key that references two other tables. My problem is how to structure the syntax so that it will accept the key. I am using
ALTER TABLE
ADD constraint FK_NAME(col) references table(col);
|
|
|
Re: Creating a foreign key that references two other tables [message #372594 is a reply to message #372572] |
Mon, 26 February 2001 15:05 |
Joachim Lindner
Messages: 30 Registered: February 2001
|
Member |
|
|
Well, it sounds a bit strange to me, at first sight, to define an FK constraint on more than
one table. Anyway ...
Your problem is not the statement syntax, but the amount of FK defining statements. In fact you need two in your example.
One referencing parent table A, the other one referencing parent table B. In order to fully enforce referential integrity you have to establish an additional
check constraint that guarantees that BOTH fk columns are either null or not null.
|
|
|