Re: References to SERIAL

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: References to SERIAL
Дата
Msg-id Pine.LNX.4.30.0012301316430.11787-100000@chapelperilous.net
обсуждение исходный текст
Ответ на References to SERIAL  (Thomas SMETS <tsmets@altern.org>)
Ответы Re: References to SERIAL  ("Oliver Elphick" <olly@lfix.co.uk>)
Список 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 по дате отправления:

Предыдущее
От: "Albert REINER"
Дата:
Сообщение: configure: what was used?
Следующее
От: "Oliver Elphick"
Дата:
Сообщение: Re: References to SERIAL