From: Richard Huxton <dev@archonet.com>
To: olaf.zanger@soli-con.com
To: PgSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: constraint/restrict
Date: Wed, 14 Feb 2001 11:32:04 -0000
Message-ID: <00a801c09679$c57a26e0$1001a8c0@archonet.com> (raw)
References: <01021409023603.01358@sino>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: dev@archonet.com, olaf.zanger@soli-con.com
Subject: Re: constraint/restrict
In-Reply-To: <00a801c09679$c57a26e0$1001a8c0@archonet.com>
References: <01021409023603.01358@sino> <00a801c09679$c57a26e0$1001a8c0@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox