When to Use Long Number and when to use text as a Primary Key?

M

Mark

Is there a rule on when to use a number as a primary key and when to use a
text field? At the moment I just decide if the primary key is too large and
is needed for foreign keys I use a number. For example, if I was to design
a table containing Transaction Types, I would create the Primary Key
(TransactionTypeID) as dr (debit) and cr (credit). Similarly if I was to
create a Unit Of Measure table my primary key would be the abbreviation of
the Unit e.g. EA, KG etc. When creating a users table in which all users
have a login username, I assign the primary key as UserID and not their
username even though they all have one and they are all unique. For a
products table if a Product Code is 5 digits long and is one for each
product and doesn't change, should this be the primary key or should I
assign an autonumber?

Thanks in advance
 
C

chris.nebinger

I've heard that numbers are faster than text. But, that would probably
only be on larger tables.

My personal preference is to use an available PK before creating an
autonumber. I would use the UserName, the ProductCode, etc. I think
it is just easier as a developer.

Just my $.02

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top