From: "Olaf Marc Zanger" <[EMAIL PROTECTED]>
> 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