Re: References to SERIAL

From: "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net>
To: Thomas SMETS <tsmets(at)altern(dot)org>
Cc: psql sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: References to SERIAL
Date: 2000-12-30 18:21:40
Message-ID: Pine.LNX.4.30.0012301316430.11787-100000@chapelperilous.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 30 Dec 2000, Thomas SMETS wrote:

> If i create a "internal pk" buy defining on a table a field SERIAL.
> How do I reference this field in the other table to set the field
> possible value ?
>
>
> create table book (
> /* This is an internal primary key for the book description */
> book_pk serial,
> .... // End of Book def
> );
>
> create table books_authors (
> ??? // I want to reference the book pk & the author pk to be able to
> make the X-ref ?
> );

You mean as a foreign key? You would do something like

create table books_authors (
book integer references book(book_pk)
on delete no action,
author integer references author(author_pk)
on delete no action,
...
);

This forces integrity between the tables so the only allowable values in
the books_authors table are those values in the referenced fields (foreign
keys).

You will probably want to look up the documentation on contraints and
foreign keys (I believe they are under the CREATE TABLE documentation).

-- Brett
http://www.chapelperilous.net/~bmccoy/
---------------------------------------------------------------------------
Did you hear that there's a group of South American Indians that worship
the number zero?

Is nothing sacred?

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Oliver Elphick 2000-12-30 19:03:34 Re: References to SERIAL
Previous Message Thomas SMETS 2000-12-30 16:39:32 References to SERIAL