Re: FOREIGN KEY questions
От | Patrick Welche |
---|---|
Тема | Re: FOREIGN KEY questions |
Дата | |
Msg-id | 20000910124643.D21418@quartz.newn.cam.ac.uk обсуждение исходный текст |
Ответ на | FOREIGN KEY questions (Neil Conway <nconway@klamath.dyndns.org>) |
Список | 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 по дате отправления: