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

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

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.
- 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


Serge Fonville


Convince Google!!
They need to support Adsense over SSL


pgsql-novice by date

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

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