creating composite foreign key from two different tables primary keys in oracle creating composite foreign key from two different tables primary keys in oracle oracle oracle

creating composite foreign key from two different tables primary keys in oracle


It's not possible to have a single foreign key referencing fields on different tables, and it makes no sense at all. A foreign key of two or more fields implies that the combination of values of the fields must be match on a single record of the referenced table, and this can't be done if the referenced fields are on different tables.

What you can do is to create two distinct foreing keys to the two tables, as following:

CREATE TABLE table3(    iid NUMBER,    Tid NUMBER,    Sid NUMBER,    CONSTRAINT pk    PRIMARY KEY (iid) USING INDEX TABLESPACE idx,    CONSTRAINT fk001 FOREIGN KEY (tid) REFERENCES table1(tid),    CONSTRAINT fk002 FOREIGN KEY (sid) REFERENCES table2(sid));