Skip site navigation (1) Skip section navigation (2)

Re: are primary keys always 'needed'

From: Serge Fonville <serge(dot)fonville(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: are primary keys always 'needed'
Date: 2010-02-28 17:17:59
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Thanks for the reply.

>> Some have a serial that is used as a foreign key in another table.
>> Some tables consist of a combination of two foreign keys (that are
>> unique together) and a field that is uniquely related to that
>> combination (but is not necessarily unique within the table)
> BTW, I forgot to mention that it's perfectly reasonable to have a
> multi-column primary key, which is what seems to be indicated in
> this type of example.  I wouldn't advocate making up a surrogate
> primary key in a linking table, if the combination of its foreign
> keys can do the job.

So when I have a table that exists only on the MANY-end of the
relation and in now way is ever to be used as a an entity in the
ONE-end of the relatonship.
There are no benefits to specifying a primary key if a combination of
two fields (that already have a unique not null constraint anyway) to
replace those with a primary key?

Are there any other benefits to a primary key other than unique not
null constraints.
For performance.
For example, if I create a primary key that is never used in any
query, but its just there'  to make the row unique.

Based on what you stated so far, I'd think:
A primary key is not necessary, but useful in uniquely identifying a record.

Thanks so far.


Serge Fonville


Convince Google!!
They need to support Adsense over SSL

In response to

pgsql-novice by date

Next:From: bill houseDate: 2010-02-28 23:01:58
Subject: Re: Function
Previous:From: Michael GlaesemannDate: 2010-02-28 17:16:02
Subject: Re: are primary keys always 'needed'

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group