Re: Primary Key Dilemma
From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 07/18/04
- Next message: Roji. P. Thomas: "Re: Primary Key Dilemma"
- Previous message: Frank Ashley: "Re: DMO - Message "[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '\'.""
- In reply to: Jeremy: "Primary Key Dilemma"
- Next in thread: Roji. P. Thomas: "Re: Primary Key Dilemma"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 18 Jul 2004 10:13:58 +0100
The reason you are having this perceived dilemma is that you haven't grasped
the difference between a Natural Key and a Surrogate Key. A Natural Key is
the subset of the attributes of an entity that uniquely identifies a row in
its table. This is often more than one column. For example if your users are
placing orders online then the key for the Orders table might be the
composite key (business_id, order_date). An IDENTITY column is never part of
the Natural Key of a table.
A Surrogate Key is an internally generated unique value (IDENTITY in SQL
Server), which for reasons of performance and to simplify administration is
sometimes used as the target of foreign key constraints in place of the
natural key. The surrogate key value is meaningless, it is purely for
internal use and should never need to be part of a composite key.
Both the Natural Key and the Surrogate Key should be declared as PRIMARY or
UNIQUE NOT NULL. In terms of *logical* design the Surrogate Key is optional
(in fact it's redundant) but the Natural Key is not. Some people will argue
that Surrogate Keys are unnecessary and just weaken your DB design while
others recommend using them for every table. In any case the IDENTITY column
shouldn't affect your decision about the keys for the tables in your system.
-- David Portas SQL Server MVP --
- Next message: Roji. P. Thomas: "Re: Primary Key Dilemma"
- Previous message: Frank Ashley: "Re: DMO - Message "[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '\'.""
- In reply to: Jeremy: "Primary Key Dilemma"
- Next in thread: Roji. P. Thomas: "Re: Primary Key Dilemma"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|