Re: FOREIGN KEY questions - Mailing list pgsql-general

From Patrick Welche
Subject Re: FOREIGN KEY questions
Date
Msg-id 20000910124643.D21418@quartz.newn.cam.ac.uk
Whole thread Raw
In response to FOREIGN KEY questions  (Neil Conway <nconway@klamath.dyndns.org>)
List pgsql-general
On Sun, Sep 10, 2000 at 12:43:08AM -0400, Neil Conway wrote:
> I'm having a bit of difficulty understanding the correct usage of
> foreign keys (I've never used them before, excuse my ignorance).
> Here's a situation where I'm trying to figure out how/if they
> should be used:
>
> One database has a group of tables with intereferential data.
> For example:
>
> CREATE TABLE messages (
>     /* ... */
>     poster  INT4 NOT NULL,
>     thread  INT4 NOT NULL
> );
>
> CREATE TABLE users (
>     id      serial
>     /* ... */
> );
>
> CREATE TABLE threads (
>     id      serial
>     /* ... */
> );

Something like

CREATE TABLE messages (
    /* ... */
    poster  INT4 NOT NULL REFERENCES users,
    thread  INT4 NOT NULL REFERENCES threads,
);

CREATE TABLE users (
    id      serial PRIMARY KEY
    /* ... */
);

CREATE TABLE threads (
    id      serial PRIMARY KEY
    /* ... */
);

cf. Bruce's book:
  http://www.postgresql.org/docs/aw_pgsql_book/node156.html

Cheers,

Patrick

pgsql-general by date:

Previous
From: Neil Conway
Date:
Subject: FOREIGN KEY questions
Next
From: "Karl F. Larsen"
Date:
Subject: Re: FOREIGN KEY questions