View Single Post
  #2  
Old January 7th, 2010, 09:58 AM posted to microsoft.public.access.tablesdbdesign
Allen Browne
external usenet poster
 
Posts: 11,706
Default AutoNumber vs. Natural Primary Keys

You will find people who strongly argue for natural keys rather than
surrogates where a simple, natural key exists. You will also find people who
always use an AutoNumber, even if there is a simple, obvious, unique,
required field that could do the job.

My personal approach is to use the natural key (rather than an autonumber)
in lookup tables. If the category name is required and unique, why not use
it? Typically I'll limit these to 24-character. You probably realize that
string matching is slower than numeric matching, but I don't find any
measurable performance difference (probably because it's indexed anyway.)
Cascading updates take care of the need to change the category name later
(e.g. if misspelled.)

A side benefit of doing this is that it avoids some of the problems Access
has with combos where the bound column is hidden.

Some developers avoid natural keys so they can write generic code that
accepts numeric key value (i.e. they don't want to write code that has to
handle Text or number values depending on which table you're using it on.
This is a non-issue for me, as I rarely pass a simple value to a function. I
find that the code is much more generic if I pass a WHERE clause rather than
a value, as this copes with more complex conditions (e.g. tables that have a
compound key.)

In general, I use autonumbers for the main tables (e.g. clients.) I find
this avoids making unjustified assumptions about what data will be unique
early in the design process.

Random autonumbers are useful if you need to replicate. I almost never use
them.

HTH.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Tokyo Alex" wrote in message
...
Dear all,

As a relative newbie to the art/science of database design, I was
wondering
if there was any consensus view on whether it's better to use an
AutoNumber
field as primary key for a table rather than select a
(human-understandable)
natural key, assuming one exists that you can guarantee will be unique.

Does the situation change between a 'main' table containing entity data
(tblCustomers, e.g.) and a lookup table you're using to store values for a
combo box?

For that matter, is there any situation where you might prefer to use a
random AutoNumber instead of an incremental one?

Any ideas and advice very much appreciated.

Thanks,
Alex.