Reputation: 168
In the table A
, I've got a composite of 3 fields as a primary key
and in the table B
I've got one of the composite (which is not unique). I'd like to reference with the table A
to ease the delete
(with ON DELETE CASCADE
).
So, am I compelled to put the other two fields in the table B and reference with this composite
or is there another solution?
Upvotes: 4
Views: 6484
Reputation: 8376
You could create a new single-column (probably sequence-generated) primary key in table A and make the existing composite key a unique key instead of a primary key. Then reference your new primary key from table B.
Upvotes: 1
Reputation: 231671
If you want to create a foreign key constraint between the two tables, the child table would have to have all the columns that comprise the primary key constraint on the parent table (which is one of the reasons that I would discourage the use of composite primary keys). If you want Oracle to automatically delete a child row when then parent row is deleted, you need a foreign key constraint with ON DELETE CASCADE
. So your options are
Upvotes: 3