Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> multiple foreign keys; can they operate in an OR relationship?
Using the below script, i wanted to know if i could create multiple
foreign keys on a single column in a child table that operate in an OR
fashion.
Table tempP1 hold one possible key, and tempP2 holds the other. I
wanted a insert into tempC to check both FK tables: tempP1 OR tempP2
has the key (which would succeed)...not tempP1 AND tempP2 have the key
(which failed)
Is this possible? am i missing something in the syntax?
Thanks.
SQL> insert into tempC(id, description, fkid) values ( 1, 'descC',2);
insert into tempC(id, description, fkid) values ( 1, 'descC',2)
*
ERROR at line 1:
ORA-02291: integrity constraint (DEVR1.FK_1) violated - parent key not
found
alter table tempC
drop constraint "FK_1";
alter table tempC
drop constraint "FK_2";
drop table tempC cascade constraints;
drop table tempP1 cascade constraints;
drop table tempP2 cascade constraints;
create table tempC
(
id number(6) not null, description varchar2(100), fkid number(2),
constraint PK_C primary key (id)
);
create table tempP1
(
id number(2) not null, description varchar2(100),
constraint PK_P1 primary key (id)
);
create table tempP2
(
id number(2) not null, description varchar2(100),
constraint PK_P2 primary key (id)
);
alter table tempC
add constraint "FK_1" foreign key (fkid) references tempP1(id);
alter table tempC
add constraint "FK_2" foreign key (fkid) references tempP2(id);
INSERT INTO tempP1 (id, description) VALUES (1,'desc1');
INSERT INTO tempP2 (id, description) VALUES (2,'desc2'); Received on Thu Sep 30 2004 - 19:35:32 CDT
![]() |
![]() |