pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: kernel.alert kernel.alert <kernel.alert@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: problem with uniques and foreing keys
Date: Sat, 6 May 2006 12:56:35 -0500
Message-ID: <20060506175635.GA23459@wolff.to> (raw)
In-Reply-To: <e24c449c0605061027t5d8c06aeoe271580c5244922f@mail.gmail.com>
References: <e24c449c0605061027t5d8c06aeoe271580c5244922f@mail.gmail.com>

On Sat, May 06, 2006 at 12:27:41 -0500,
  "kernel.alert kernel.alert" <kernel.alert@gmail.com> wrote:
> Hi list...
> 
> Please i have a problem with this...
> 
> 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),
> 
>  ubicacion_sala     varchar(45) default NULL,
>  primary key(id_empresa,id_casino,id_tipo_maquina,id_maq_casino)
> );
> 
> --------------------------------------------------------
> 
> When i'm gonna to create the last table i got this error:
> 
> ERROR:  no hay restriccion unique que coincida con las columnas dadas en la
> tabla referida <<casino>>
> 
> That in english is like .. there is no a unique constraint with columns
> referred  in casino table.
> 
> 
> Please where is the problem...

Unless there is a performance problem, id_empresa should not appear in the
maq_casino table at all, since it is derivable from id_casino.

Is id_empresa really allowed to be NULL in casino?

If there is an actual performance problem and you really need to have it in
the mag_casino table, then you want to add another unique key (id_casino,
id_empresa) in casino and then change casino_mag to have a foreign key
reference on (id_casino, id_impresa) to casino instead of the individual
references you have now.

If id_empresa in casino_mag is not supposed to be tied to the value of
id_casino (which I doubt is the case), then it should be referencing
empresa instead of casino.



view thread (5+ messages)  latest in thread

Message-ID: <20060506175635.GA23459@wolff.to>
Permalink:  ../20060506175635.GA23459@wolff.to/
Also on:    postgresql.org/message-id/20060506175635.GA23459@wolff.to

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, kernel.alert@gmail.com
  Subject: Re: problem with uniques and foreing keys
  In-Reply-To: <20060506175635.GA23459@wolff.to>

* 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