Re: constraint/restrict
От | Richard Huxton |
---|---|
Тема | Re: constraint/restrict |
Дата | |
Msg-id | 00a801c09679$c57a26e0$1001a8c0@archonet.com обсуждение исходный текст |
Ответ на | constraint/restrict (Olaf Marc Zanger <olaf.zanger@soli-con.com>) |
Список | pgsql-sql |
From: "Olaf Marc Zanger" <olaf.zanger@soli-con.com> > hi there, > > with two tables i want to make some constraint-restrictions > > to make sure that now country-row is deleted if there is still a country_id > in address table. > > e.g. > > address: 1, 2, ... > country: 2, ... > > now country wouldn't be allowed to be deleted. > > how to do that? You want a foreign-key (only in version 7) - check the reference manual for CREATE TABLE - and look for the keyword REFERENCES Basically, it's like: create table foo (fooid serial unique, footxt text); create table bar (barid serial, barfoo int4 references foo (fooid), bartxt text); Then after a few inserts... delete from foo where fooid=1; ERROR: <unnamed> referential integrity violation - key in foo still referenced from bar - Richard Huxton
В списке pgsql-sql по дате отправления: