What to choose for primary key in a relational database

Anything simple.
Anything simple but not something the user knows about.

A 32 bit integer, a GUID, a string. But not the CustomerNumber or PostalCode or EmailAddress. No matter what the user/customer/client says – those things are not unique. I have been harrassing customers whether the CustomerNumber is unique or not. It has been unique for two weeks until someone remembered about foreign offices with their own numbering system or that they sometimes are changed.

Alas – do not use anything you find in the business logic as primary key.

A more technical comment on why we use int is found here.

Tags: , ,

One Response to “What to choose for primary key in a relational database”

  1. […] A comment of what to use as a primary key is found here. […]

Leave a Reply