Re: surrogate key or not? - Mailing list pgsql-sql

From Tom Lane
Subject Re: surrogate key or not?
Date
Msg-id 19813.1090591668@sss.pgh.pa.us
Whole thread Raw
In response to Re: surrogate key or not?  (Michael Glaesemann <grzm@myrealbox.com>)
Responses Re: surrogate key or not?  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List pgsql-sql
Michael Glaesemann <grzm@myrealbox.com> writes:
> You appear to be misunderstanding the purpose of a primary key. A 
> primary key is used to ensure there is a way to identify each row 
> uniquely. It is quite independent of which columns you may or may not 
> want to search on. If name is not going to be necessarily unique in the 
> table, it isn't a primary key.

The other standard reason for using a made-up value as primary key is
that it's under your control and you can guarantee it isn't going to
change: one record will have the same primary key for its entire life,
which vastly simplifies handling of foreign keys and so forth.

If you use any real-world datum as primary key you necessarily buy into
tracking changes in that real-world value.  And handling duplicates.
Names are certainly not unique, and they do change (marriage, etc) and
people do miskey them and then expect to be able to fix the error later.

As Achilleus' nearby story shows, you can have these problems (certainly
the misentry part) even with imported data that is allegedly someone
else's primary key; part numbers, USA social-security numbers, etc.
        regards, tom lane


pgsql-sql by date:

Previous
From: Janning Vygen
Date:
Subject: Re: surrogate key or not?
Next
From: Josh Berkus
Date:
Subject: Re: surrogate key or not?