Check constraints on two tables in Oracle

610 Views Asked by At

I have two tables with a one-to-one relationship (and relationship is mandatory from one side only). As follows:

create table PRS (
  id number(18) not null,
  common_code varchar2(10),
  constraint pk_prs primary key (id));

create table RLP {
  id number(18),
  spec_code varchar2(20),
  constraint pk_rlp primary key (id),
  constraint fk_rlp_prs foreign key (id) references prs(id) on delete cascade);

So the problem is when inserting a record in RLP at least one of common_code or spec_code must have value.

Is it possible to enforce this constraint using a constraint or the only solution is having a trigger?

1

There are 1 best solutions below

0
On BEST ANSWER

It seems there is no way to create a constraint on two tables, and the only solution is to create a trigger to throw an exception on desired situation.