sql - Oracle - Having foreign keys in more than one table -
i'm not sure if 1 can need have foreign key reference 2 tables.
table1 has 2 columns (a pk, b) table2 has 2 columns (c pk, d)
table3 has 3 columns (a pk, b pk, e) , made of first 2 table.
what hoping following:
create table table3 ( varchar2 (4), c varchar2 (10), e char (1), constraint pk_a_c primary key (a, c), constraint fk_a_c foreign key (a, c) references (table1.a, table2.b) );
i hope makes sort of sense.
thanks
james
a given foreign key constraint describes relationship 1 child table 1 parent table.
you can, however, have 2 foreign key constraints, each pointing respective table:
create table table3 ( varchar2 (4), c varchar2 (10), e char (1), constraint pk_a_c primary key (a, c), constraint fk_a foreign key (a) references table1(a), constraint fk_b foreign key (c) references table2(b) );
Comments
Post a Comment