Re: foreign SERIAL keys in weak entity primary keys

From: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
To: Thomas Hood <s0096184(at)sms(dot)ed(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: foreign SERIAL keys in weak entity primary keys
Date: 2003-03-10 07:31:02
Message-ID: Pine.LNX.4.44.0303100827500.18598-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 10 Mar 2003, Thomas Hood wrote:

> CREATE TABLE Items (
> IID SERIAL PRIMARY KEY, --Item ID
> Name TEXT NOT NULL, -- Item name
> SID INTEGER REFERENCES Suppliers); --supplier

> CREATE TABLE Inventory (
> IID SERIAL REFERENCES Items,
> PackSize INTEGER NOT NULL, --no. of items in a pack
> QOH INTEGER NOT NULL, --quantity of this size pack(of this item) on shelf.
> WID SERIAL REFERENCES Warehouses, --warehouse where shelved
> Price DECIMAL(5,2) NOT NULL,
> PRIMARY KEY (IID, PackSize));

> The table Inventory has tuples which have minimal candidate key of (IID,
> PackSize), yet for some reason it insists on making IID * WID unique
> columns!

Why do you need sequences for Inventory.IID and Inventory.WID. Just make
them into integers that references the other tables. By declating them as
SERIAL you say that you want sequences generated for these columns. You
already have a sequence that generate Items.IID, you don't need another
one.

--
/Dennis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message frank_lupo 2003-03-10 07:54:48 function param problem in 7.3
Previous Message Tom Lane 2003-03-10 04:12:16 Re: foreign SERIAL keys in weak entity primary keys