Received: from www-uk-05.digiserve.com ([195.172.23.63]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1EBYex18878 for ; Wed, 14 Feb 2001 06:34:40 -0500 (EST) (envelope-from dev@archonet.com) Received: from mainbox.archonet.com (mwynhau.demon.co.uk [193.237.186.96]) by www-uk-05.digiserve.com (8.9.1/8.9.1) with ESMTP id LAA00728; Wed, 14 Feb 2001 11:35:26 GMT Received: from client (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with SMTP id 1A69C2A3AA; Wed, 14 Feb 2001 11:32:13 +0000 (GMT) Message-ID: <00a801c09679$c57a26e0$1001a8c0@archonet.com> From: "Richard Huxton" To: , "PgSQL-SQL" References: <01021409023603.01358@sino> Subject: Re: constraint/restrict Date: Wed, 14 Feb 2001 11:32:04 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200102/252 X-Sequence-Number: 1443 From: "Olaf Marc Zanger" > 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: referential integrity violation - key in foo still referenced from bar - Richard Huxton