Thread: Primary key question

Primary key question

From
Richard Rowell
Date:
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...

Thanx in advance!

Re: Primary key question

From
Ron Peterson
Date:
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

newbie question

From
"Mike Sears"
Date:
is it possible to pull a column from a postgres table then have it linked
via html and php to the corresponding row. If so how would that be
accomplished?