Thread: inheritance and FK

inheritance and FK

From
Oleg Lebedev
Date:
I am trying to create two tables: parent and child. Child inherits from the parent and has a foregn key (FK) referencing parent's primary key (PK). Suppose parent table has one row with PK = 1 and I have one row in the child table with FK=1 and PK=2. Now, I want to insert another row in the child table with FK = 2, however it won't let me do this, since parent table does not have a record with PK = 2.
I was expecting that children tables will also be searched when verifying a foreign key constraint referencing the parent table.
Is there a way to force this kind of "hierarchical" foreign key constraint check?
 
Thanks.
 
Oleg

*************************************

This email may contain privileged or confidential material intended for the named recipient only.
If you are not the named recipient, delete this message and all attachments.
Any review, copying, printing, disclosure or other use is prohibited.
We reserve the right to monitor email sent through our network.

*************************************

Re: inheritance and FK

From
Stephan Szabo
Date:
On Mon, 3 Mar 2003, Oleg Lebedev wrote:

> I am trying to create two tables: parent and child. Child inherits from
> the parent and has a foregn key (FK) referencing parent's primary key
> (PK). Suppose parent table has one row with PK = 1 and I have one row in
> the child table with FK=1 and PK=2. Now, I want to insert another row in
> the child table with FK = 2, however it won't let me do this, since
> parent table does not have a record with PK = 2.
> I was expecting that children tables will also be searched when
> verifying a foreign key constraint referencing the parent table.
> Is there a way to force this kind of "hierarchical" foreign key
> constraint check?

Not currently.  Currently the check is applied only to the named table.
In general, inheritance needs alot of work, and we need a comprehensive
plan for all the problems (for example, primary keys also don't inherit).