From: | "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk> |
---|---|
To: | "Pausas Fuentes, Jaume" <JPausas(at)alehop(dot)com> |
Cc: | pgsql-sql(at)postgreSQL(dot)org, olly(at)linda(dot)lfix(dot)co(dot)uk |
Subject: | Re: [SQL] foreign key implementation |
Date: | 2000-01-13 21:21:16 |
Message-ID: | 200001132121.VAA23887@linda.lfix.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Pausas Fuentes, Jaume" wrote:
>Hi
>
>Anybody have an implementation of the sql foreign key?
>
>Reading the manual it says that I must use the create trigger command
>but how to implement a procedure to do what foreing key does?
You need the refint package out of contrib.
Then use commands like these:
create database bray;
\connect bray
-- refint functions (from postgresql-contrib package). These are
-- needed until foreign keys are implemented in PostgreSQL
\i contrib/spi/refint.sql
create table area
(
id char(2) primary key,
name text not null,
vat_class char(1) default 'S'
);
create trigger area_fref
before DELETE or UPDATE on area
for each row execute procedure
check_foreign_key (1, 'restrict', 'id',
'customer', 'area'
);
create table customer
(
acs_code char(8),
...
area char(2) references area (id),
...
);
create trigger customer_pkref2
before INSERT or UPDATE on customer
for each row execute procedure
check_primary_key ('area', 'area', 'id');
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP key from public servers; key ID 32B8FAA1
========================================
"For the LORD is good; his mercy is everlasting; and
his truth endureth to all generations."
Psalms 100:5
From | Date | Subject | |
---|---|---|---|
Next Message | Michael McCarthy | 2000-01-14 08:09:48 | key set delete query |
Previous Message | Pausas Fuentes, Jaume | 2000-01-13 11:14:24 | foreign key implementation |