Re: [GENERAL] using ID as a key
От | Ed Loehr |
---|---|
Тема | Re: [GENERAL] using ID as a key |
Дата | |
Msg-id | 389B0811.877208CB@austin.rr.com обсуждение исходный текст |
Ответ на | using ID as a key (sheila bel <sheilabel@hotmail.com>) |
Список | pgsql-general |
sheila bel wrote: > > Hi, > > I'm new to data base design so please bare with me if my > question is so basic.. > I'm designing a database, two of the tables are EMPLOYEES and > AGENCIES. I need an ID for each of them. I would also need to > have the agencyID in the EMPLOYEES table so that I can identify > which agency they belong to something like a foreign key. I know > postgreSQL does not support it so how do I implement this ? > What kind of data type should I use for the ID ? Sheila: checkout the SERIAL type. It is quite useful for this purpose, as in... CREATE TABLE foo ( key_id SERIAL, ... CREATE TABLE bar ( key_id SERIAL, foo_key_id INTEGER NOT NULL, -- foreign key to foo ... Lots of discussion in the archive on how to retrieve a new value for the purpose of a foreign key (keywords: SERIAL, nextval, sequence). http://www.postgresql.org/docs/postgres/datatype.htm#AEN842 Cheers, Ed Loehr
В списке pgsql-general по дате отправления: