referential integrity for insert

From: Ivan Horvath <pillesoft(at)yahoo(dot)co(dot)uk>
To: pgsql-new <pgsql-novice(at)postgresql(dot)org>
Subject: referential integrity for insert
Date: 2002-03-06 09:49:26
Message-ID: 20020306094926.89268.qmail@web14704.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

i got two tables with the following structures:
create table unit (
unit_id int4 not null primary key,
unit_name varchar(10) not null)

create table plant_unit (
pu_id int4 not null primary key,
pu_code varchar(15),
unit_id int4 not null references unit (unit_id)
match all on delete restrict on update cascade)

that means the two tables are connected to each other
by the unit_id field. i cannot delete records from the
unit table if there is a relation in the plant_unit
table, and when i update the unit_id field in the unit
table the system will update all matching records in
the plant_unit table as well.

my question is how can i avoid to insert record into
the plant_unit table, when the specified unit_id is
not available in the unit table.

do i have to use trigger, or i miss something in the
constraint, or whatelse?

thanks

Ivan

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message ghaverla 2002-03-06 10:13:19 Re: index item size 4496 exceeds maximum 2713
Previous Message Faudzy Sulaiman 2002-03-06 07:00:36 Postmaster with -i