Re: Primary key question - Mailing list pgsql-general

From Ron Peterson
Subject Re: Primary key question
Date
Msg-id 396384E0.A3A9B908@yellowbank.com
Whole thread Raw
In response to Primary key question  (Richard Rowell <rrowell@spamfree.com>)
Responses newbie question  ("Mike Sears" <matrix@vianet.ca>)
List 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 by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: PostgreSQL 7.1
Next
From: The Hermit Hacker
Date:
Subject: Re: proposed improvements to PostgreSQL license