From: | Ed Loehr <eloehr(at)austin(dot)rr(dot)com> |
---|---|
To: | sheila bel <sheilabel(at)hotmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: [GENERAL] using ID as a key |
Date: | 2000-02-04 17:10:41 |
Message-ID: | 389B0811.877208CB@austin.rr.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | George | 2000-02-04 17:14:12 | (no subject) |
Previous Message | sheila bel | 2000-02-04 16:41:16 | using ID as a key |