Re: [GENERAL] using ID as a key - Mailing list pgsql-general

From Ed Loehr
Subject Re: [GENERAL] using ID as a key
Date
Msg-id 389B0811.877208CB@austin.rr.com
Whole thread Raw
In response to using ID as a key  (sheila bel <sheilabel@hotmail.com>)
List 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 by date:

Previous
From:
Date:
Subject: Re: [GENERAL] using ID as a key
Next
From: George
Date:
Subject: (no subject)