Re: Primary key question

Поиск
Список
Период
Сортировка
От Ron Peterson
Тема Re: Primary key question
Дата
Msg-id 396384E0.A3A9B908@yellowbank.com
обсуждение исходный текст
Ответ на Primary key question  (Richard Rowell <rrowell@spamfree.com>)
Ответы newbie question  ("Mike Sears" <matrix@vianet.ca>)
Список pgsql-general
Richard Rowell wrote:
>
> I'm creating a database with 20 tables or so.  I have come to the
> table that will likely tie many of these tables together, that is
> every single field in this table will be a foriegn key.  My question
> is, rather then include all of the fields into the primary key of this
> table, and therefore include all of these fields into any table that
> will reference this one, would it be politically correct to just give
> each entry an integer as a primary key and scan for dupes in a
> trigger?  It sure seems like it would cut down on the complexity of
> the whole thing...

If I understand correctly, it sounds like what you want to do is
establish a UNIQUE constraint on your foreign keys, and add a sequenced
integer to be the primary key for this table.  E.G. -

CREATE TABLE test (
    fkey1    INTEGER REFERENCES ...,
    fkey2    INTEGER REFERENCES ...,
    id    SERIAL PRIMARY KEY,
    UNIQUE(fkey1,fkey2)
);

________________________
Ron Peterson
rpeterson@yellowbank.com

В списке pgsql-general по дате отправления:

Предыдущее
От: The Hermit Hacker
Дата:
Сообщение: Re: PostgreSQL 7.1
Следующее
От: The Hermit Hacker
Дата:
Сообщение: Re: proposed improvements to PostgreSQL license