foreign key implementation
foreign key implementation
От:
"Pausas Fuentes, Jaume" <JPausas@alehop.com>
Дата:
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? Jaume Pausas
Re: [SQL] foreign key implementation
От:
"Oliver Elphick" <olly@lfix.co.uk>
Дата:
"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.Elphick@lfix.co.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
Re: [SQL] foreign key implementation
От:
wieck@debis.com (Jan Wieck)
Дата:
> 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? The current development tree includes this. Will be released with version 7.0. Not completely finished up to now, but enough to get a feeling. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #========================================= wieck@debis.com (Jan Wieck) #