Re: FAQ? factors influencing choice of data type for primary key
From: Chris (ganjula_at_hotmail.com)
Date: 04/19/04
- Next message: Dan: "Error with Field Options tab when importing table"
- Previous message: Tim Ferguson: "Re: Whats the best way of doing this?"
- In reply to: John Vinson: "Re: FAQ? factors influencing choice of data type for primary key"
- Next in thread: TC: "Re: FAQ? factors influencing choice of data type for primary key"
- Reply: TC: "Re: FAQ? factors influencing choice of data type for primary key"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 19 Apr 2004 11:48:38 -0700
Thanks, John, for the additional overviews and details
last week (I've been out of town for 5 days). That's
the kind of info I was looking for to help me make the
best design decisions, especially the specifics about
Access implementation as opposed to theoretical
considerations.
Considering that this is, apparently, a recurring
question about a significant (and contentious) issue,
it seems it ought to be in a FAQ somewhere... is there
a FAQ associated with these forums to save seekers
and responders from covering the same ground over
and over again? I found it difficult to zero in
on useful messages on this topic by just searching the
forum archives.
Many thanks,
Chris
>-----Original Message-----
>On Wed, 14 Apr 2004 08:22:00 -0700, "Chris"
<ganjula@hotmail.com>
>wrote:
>
>>What factors, if any - performance? db size? other? -
>>are important in choosing the data type for a primary
>>key? Since one always has the option of using, for
>>example, an Autonumber as a primary key, are there
>>times when that choice is prefered even though there
>>is some other unique attribute in the data itself?
>
>This can be a contentious topic - flamewars have resulted
from this
>question, though lately we've seen mostly polite
disagreement rather
>than attacks! <let's hope that continues>
>
>>For example, a simple single-attribute table of allowed
>>categories (to be used as a lookup table for assigning
>>records from another table to different categories)
>>could use the category name itself as a primary key -
>>all category names will be unique. But does it make
>>sense to use this text field as a foreign key in
>>another table, or is it better to create an additional
>>autonumber field in the category table?
>
>In that case I'd use the textfield... with some caveats.
See below.
>
>>I think what I'm really wondering about is the
>>implementation of primary/foreign keys: if there is
>>only a single text attribute in a table, used as a
>>primary key, what gets stored in the other table where
>>it is a foreign key? Is it the text itself, which
>>could be quite sizable?
>
>It is the text itself. There's nothing special about a
field that's
>being used as a foreign key - it's *just a field*, like
any other
>field; it's a FK in terms of how it's used, not in terms
of the nature
>of the field.
>
>>Or does Access use internal
>>record numbers or the field indexes as the value for
>>the foreign key?
>
>No. There are no (usable) internal record numbers.
>
>>I would expect performance and/or
>>storage size penalties if the actual primary key
>>value (text, in this example) is stored in the other
>>table as the foreign key.
>
>That's the main argument against them... but what you win
on the
>swings, you lose on the roundabouts. If you have the
actual value in
>the table, then only that table needs to be included in a
Query; you
>don't need to bring the lookup table or any indexes into
memory in
>order to get the value, so search performance can be
better. The
>downside is that the database will be bigger. Access
doesn't store
>trailing blanks, so the allocated size of the field isn't
really
>relevant; but if your categories average 16 bytes, in a
million-record
>table you'll use 16 MByte of foreign key values, vs. 4
MByte for
>4-byte Long Integers.
>
>In practice, if the Primary Key is *unique* - there can
never be
>duplicates; *stable* - it will rarely or never change;
and (ideally)
>short - I'd use a natural key by preference over a
surrogate key such
>as an autonumber. In many cases (tables of People for
instance) there
>is no obvious stable, short, unique key, though; and
sometimes the
>"natural" key might consist of five or six fields. Some
folks (Tom
>Ellison prominent amongst them) prefer to use such
natural keys almost
>exclusively and claim that there is little or no
performance hit;
>others disagree.
>
>
> John W. Vinson[MVP]
> Come for live chats every Tuesday and Thursday
>http://go.compuserve.com/msdevapps?loc=us&access=public
>.
>
- Next message: Dan: "Error with Field Options tab when importing table"
- Previous message: Tim Ferguson: "Re: Whats the best way of doing this?"
- In reply to: John Vinson: "Re: FAQ? factors influencing choice of data type for primary key"
- Next in thread: TC: "Re: FAQ? factors influencing choice of data type for primary key"
- Reply: TC: "Re: FAQ? factors influencing choice of data type for primary key"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|