From: | "Richard Huxton" <dev(at)archonet(dot)com> |
---|---|
To: | <olaf(dot)zanger(at)soli-con(dot)com>, "PgSQL-SQL" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: constraint/restrict |
Date: | 2001-02-14 11:32:04 |
Message-ID: | 00a801c09679$c57a26e0$1001a8c0@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
From: "Olaf Marc Zanger" <olaf(dot)zanger(at)soli-con(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Ines.Klimann | 2001-02-14 12:13:01 | Oracle8 / PostgreSQL |
Previous Message | Olaf Marc Zanger | 2001-02-14 08:02:54 | constraint/restrict |