Chield Serial

Поиск
Список
Период
Сортировка
Искать

Chield Serial

От:
lucas@presserv.org
Дата:
Hi.
Is there a way to make a serial columm that works with father table???
I.e:I have created a table called "vending" and its chield table called "items".The items table have a serial columm, but I need the serial colum starts with 0
for each vending.
create table vending ( id serial primary key,  --Ok, this serial: 0 - 9999xxx date_ date);create table items ( vending_id references vending, items_id   serial,  -- THIS SERIAL NEED to start 0 for each vending_id primary key (vending_id,items_id));insert into vending values (1,now());insert into vending values (2,now());insert into items values (1);insert into items values (1);insert into items values (2);insert into items values (2);select * from items;
vending_id  |  items_id         1  |         1         1  |         2         2  |         3    <<=== Here! The items_id need to be 1 (start again
for each vending_id)         2  |         4    <<==
Thanks all.

FAQ