Re: problem with uniques and foreing keys

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "kernel(dot)alert kernel(dot)alert" <kernel(dot)alert(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: problem with uniques and foreing keys
Date: 2006-05-06 18:57:39
Message-ID: 20060506115248.G47923@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bryce Nesbitt 2006-05-06 19:46:13 Re: grant select on database demo to user
Previous Message kernel.alert kernel.alert 2006-05-06 18:43:48 Re: problem with uniques and foreing keys