Re: [SQL] foreign key implementation

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: [SQL] foreign key implementation
Дата
Msg-id 200001132121.VAA23887@linda.lfix.co.uk
обсуждение исходный текст
Ответ на foreign key implementation  ("Pausas Fuentes, Jaume" <JPausas@alehop.com>)
Список pgsql-sql
"Pausas Fuentes, Jaume" wrote: >Hi > >Anybody have an implementation of the sql foreign key? > >Reading the manual it
saysthat 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
ID32B8FAA1                ========================================    "For the LORD is good; his mercy is everlasting;
and     his truth endureth to all generations."                                             Psalms 100:5 
 




В списке pgsql-sql по дате отправления:

Предыдущее
От: "Pausas Fuentes, Jaume"
Дата:
Сообщение: foreign key implementation
Следующее
От: Michael McCarthy
Дата:
Сообщение: key set delete query