are primary keys always 'needed'

From: Serge Fonville <serge(dot)fonville(at)gmail(dot)com>
To: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: are primary keys always 'needed'
Date: 2010-02-28 16:38:34
Message-ID: 680cbe0e1002280838h17eee864w9f2ceb1b632e65bf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I was wondering if primary keys are always needed.
What I understand;
- The value of a primary key is unique per table
- Primary keys are unique and not null.

I have a couple of tables.
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)
Others have no unique field or combination at all

For the tables that are only used in the foreign part of the
relationship(s), is there an added value for user of a surrogate
primary key, which will never be referenced.

I did a lot of googling and found very varying opinions.
Mainly:
- Always use a primary key, no reason why, it's just 'better'
- Use primary keys when it makes sense.

How do I determine what 'sense' or 'better' mean?

Thanks for all the feedback

Regards,

Serge Fonville

--
http://www.sergefonville.nl

Convince Google!!
They need to support Adsense over SSL
https://www.google.com/adsense/support/bin/answer.py?hl=en&answer=10528
http://www.google.com/support/forum/p/AdSense/thread?tid=1884bc9310d9f923&hl=en

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-02-28 17:02:35 Re: are primary keys always 'needed'
Previous Message Bruce Momjian 2010-02-28 01:42:02 Re: Browsing through the Postgres source