Re: References to SERIAL - Mailing list pgsql-sql

From Brett W. McCoy
Subject Re: References to SERIAL
Date
Msg-id Pine.LNX.4.30.0012301316430.11787-100000@chapelperilous.net
Whole thread Raw
In response to References to SERIAL  (Thomas SMETS <tsmets@altern.org>)
Responses Re: References to SERIAL  ("Oliver Elphick" <olly@lfix.co.uk>)
List 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?



pgsql-sql by date:

Previous
From: "Albert REINER"
Date:
Subject: configure: what was used?
Next
From: "Oliver Elphick"
Date:
Subject: Re: References to SERIAL