From: Gianluca Riccardi <ml-reader@moonwatcher.it>
To: pgsql-sql@postgresql.org
Subject: Re: DB design and foreign keys
Date: Wed, 14 Dec 2005 11:25:50 +0100
Message-ID: <439FF32E.7030004@moonwatcher.it> (raw)
In-Reply-To: <c2d9e70e0512131032h6591086dwfc73ef57a9c2503b@mail.gmail.com>
References: <439F0FE8.1050503@moonwatcher.it>
<c2d9e70e0512131032h6591086dwfc73ef57a9c2503b@mail.gmail.com>
Jaime Casanova wrote:
> [...unnecesary...]
>
>
>> CREATE TABLE orders (
>> id serial,
>> order_code serial,
>> customer_code integer REFERENCES customers (customer_code) NOT NULL,
>> order_date time without time zone NOT NULL,
>> remote_ip inet NOT NULL,
>> order_time timestamp with time zone NOT NULL,
>> order_type varchar(10) NOT NULL,
>> state varchar(10) NOT NULL,
>> PRIMARY KEY (id, order_code)
>>
>
> ^^^^^^^^^^^^^^^^^^^
>
>
>> );
>>
>
> [...unnecesary...]
>
>
>> CREATE TABLE order_items (
>> id serial,
>> order_code integer REFERENCES orders (order_code) NOT NULL,
>>
>
>
> ^^^^^^^^^^^^^^
> [...unnecesary...]
>
>
>> ERROR: there is no unique constraint matching given keys for referenced
>> table "orders"
>>
>
>
> this is because the PK in the orders table has two fields not one...
> so it founds no unique index on orders(order_code)
>
>
>
then, what would you suggest, to remove the primary key from the 'id'
column? or to remove the 'id' column at all?
>
>
> --
> Atentamente,
> Jaime Casanova
> (DBA: DataBase Aniquilator ;)
>
>
thank you for your response, regards,
Gianluca Riccardi
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: ml-reader@moonwatcher.it
Subject: Re: DB design and foreign keys
In-Reply-To: <439FF32E.7030004@moonwatcher.it>
* 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