Re: FOREIGN KEY questions

From: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: FOREIGN KEY questions
Date: 2000-09-10 11:46:43
Message-ID: 20000910124643.D21418@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Karl F. Larsen 2000-09-10 12:19:54 Re: FOREIGN KEY questions
Previous Message Neil Conway 2000-09-10 04:43:08 FOREIGN KEY questions