Subject Re: [firebird-support] Foreign Key on 2 or more columns
Author Mark Rotteveel
svanderclock wrote:
> hello,
>
> in tableA i have some record with the field ID_contact that point to the table ContactA or to the table ContactB. so in this way i can not create a foreign key on my field ID_Contact.
>
> How to do ? i thing by stored procedure, but what is the best way and the most efficient way to do that in store procedure ?

You are not being very clear with your problem, but solutions can be:
1) Use multiple foreign keys
2) Use additional link tables
3) Create 'super'-table (as in superclass) so both ContactA and ContactB
share the same primary key space and use a discriminator value to see if
it is a type A or type B
4) My favorite: reconsider your design. Without further details it is
very likely your design is simply not optimal.
5) If all else fails: use triggers for integrity checking.


--
Mark Rotteveel