Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DD6379FB908 for ; Tue, 27 Mar 2007 14:42:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 72042-02-9 for ; Tue, 27 Mar 2007 14:42:22 -0300 (ADT) X-Greylist: delayed 00:06:38.892566 by SQLgrey-1.7.4 Received: from rrr1-v3.mail.re4.yahoo.com (rrr1-v3.mail.re4.yahoo.com [216.39.53.4]) by postgresql.org (Postfix) with SMTP id 4827C9FB890 for ; Tue, 27 Mar 2007 14:42:21 -0300 (ADT) Received: (qmail 42904 invoked from network); 27 Mar 2007 17:35:40 -0000 Received: from web54310.mail.yahoo.com (206.190.49.120) by rrr1-v3.mail.re4.yahoo.com with SMTP; 27 Mar 2007 17:35:40 -0000 Received: (qmail 67803 invoked by uid 60001); 27 Mar 2007 17:35:37 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=LmtUKzW3dwlU9a4JbBgNA8+IaBdvxcEMzbtSDB/Ocqg34ryMG+K/i94/LonFpaAsjV3Hh57idbv9bA8ohfhDfCfGzqBoWbmpEHU+BqtPd11Me+yKQt8tukex16SE6N0iHprwvb5YypRInSTrp1p4kMenKAwA/IZMHmNavfWKxwI=; X-YMail-OSG: _EfX0WUVM1mvqT2AAyBqRZmTUsmO7RUuTGN_Ib7ha3LgLHhh10BMt1s66645bYn7N7sEmBFFK4xym1lldwb7Y_X_k_CIWhhOV3uj2YSG9mrS9wf.rbrsEDE1WWhhEA-- Received: from [24.10.123.39] by web54310.mail.yahoo.com via HTTP; Tue, 27 Mar 2007 10:35:37 PDT Date: Tue, 27 Mar 2007 10:35:37 -0700 (PDT) From: chester c young Subject: Re: Foreign Unique Constraint To: Jon Horsman Cc: sql pgsql In-Reply-To: <4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <415536.67726.qm@web54310.mail.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/322 X-Sequence-Number: 27960 > > create table table1 ( > id SERIAL PRIMARY KEY > extension UNIQUE, > > ) > > create table table2 ( > id SERIAL PRIMARY KEY > extension UNIQUE, > > ) > > Basically table 1 and table 2 both have the concept of an extension > that must be unique but the rest of the info in the tables are > different. I need to ensure that if i add an entry to table 1 with > extension 1000 that it will fail if there is already an entry in > table2 with the same extension. use a pre-insert triggers - one for each table. include something like if exists( select 1 from table2 where extension=new.extension ) then raise exception ... end if; ____________________________________________________________________________________ Expecting? Get great news right away with email Auto-Check. Try the Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html