X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4FB029FA2DB for ; Sat, 6 May 2006 15:57:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 31796-06 for ; Sat, 6 May 2006 15:57:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id CD9C79F9C9E for ; Sat, 6 May 2006 15:57:40 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 4968D3505A; Sat, 6 May 2006 11:57:39 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 453BE34F0C; Sat, 6 May 2006 11:57:39 -0700 (PDT) Date: Sat, 6 May 2006 11:57:39 -0700 (PDT) From: Stephan Szabo To: "kernel.alert kernel.alert" Cc: pgsql-sql@postgresql.org Subject: Re: problem with uniques and foreing keys In-Reply-To: Message-ID: <20060506115248.G47923@megazone.bigpanda.com> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/70 X-Sequence-Number: 25101 On Sat, 6 May 2006, kernel.alert kernel.alert wrote: > I create the follow tables... > > -------------------------------------------------------- > > CREATE TABLE empresa ( > id_empresa integer NOT NULL primary key, > nombre varchar(45), > ); > CREATE TABLE casino ( > id_casino integer NOT NULL, > id_empresa integer REFERENCES empresa(id_empresa), > > nombre varchar(45), > > primary key(id_casino,id_empresa) > ); > CREATE TABLE maq_casino ( > id_empresa integer NOT NULL REFERENCES casino(id_empresa), > id_casino integer NOT NULL REFERENCES casino(id_casino), You probably want a table level constraint like: foreign key (id_casino, id_empresa) references casino(id_casino, id_empresa) That's not the same as two single-column constraints which is what you have above.