Re: Newbie question
Date: Mon, 20 Jun 2005 20:46:33 +0100
Message-ID: <11be745cc3crpa1_at_corp.supernews.com>
Jon Heggland wrote:
> advantages of surrogate keys vs. natural keys are that they are stable
> (I.e. they don't change), and they are never unknown.
With SQL DBMSs (which force some physical aspects to follow directly from the logical model) there can also be advantages to using a "smaller" (e.g. a single 8 byte int vs a 20 char string or a combination of 2/3 attributes) domain for the key, as it simplifies, and may speed up, comparisons on FKs/joins (and might even save some space too).
> (But that does not mean that you shouldn't record any natural key(s) as
> well, and designate them as keys, too. The distinction between
> "primary" and "alternate" keys really *is* bogus.)
Agreed -- most of the damage done by the use of surrogates is due to designers then thinking "job done" and failing to define/enforce the uniqueness of the natural keys.
> Note that the use of surrogate keys does not force you to present them
> in the user interface. Natural keys are often better for that, but they
> are not mutually exclusive in that regard.
Moreover, as Joe Celko often points out, any key that is used in the UI should have check digits or similar to catch data entry errors -- which makes SQL Server's IDENTITY and equivalent constructs pretty much unusable (directly) for such surrogate keys.
Misha Received on Mon Jun 20 2005 - 21:46:33 CEST