Re: foreign SERIAL keys in weak entity primary keys

Поиск
Список
Период
Сортировка
От Dennis Björklund
Тема Re: foreign SERIAL keys in weak entity primary keys
Дата
Msg-id Pine.LNX.4.44.0303100827500.18598-100000@zigo.dhs.org
обсуждение исходный текст
Ответ на foreign SERIAL keys in weak entity primary keys  ("Thomas Hood" <s0096184@sms.ed.ac.uk>)
Список 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


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: foreign SERIAL keys in weak entity primary keys
Следующее
От: "frank_lupo"
Дата:
Сообщение: function param problem in 7.3