Varchar as a PK

  • Hi,

    How good is to set a table with a varchar(20) as a PK?.  Would it be better to set it as a char(20).

    I am storing equipments and was defining a column named Description varchar(20) as the PK, I was looking example Databases and all define an identity int value for the PK, even though I think this shouldn't be like that.

    Any suggestion?

    thanks

    Kindest Regards,

    @puy Inc

  • You may want to read this thread on the whole subject of identity primary keys vs. natural keys.  As you might be able to see from the debate on this thread, it can be a very controversial subject among database designers.  I will just say that I prefer using identity primary keys, and let you read through the thread to see the pros and cons.

    Article Discussion: Identity and Primary Keys

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6136

     

     

     

  • I concur with Michael.  I use indentity integers as primary keys almost exclusively.  I place a Unique constraint on the natural key column if it seems advisable for data base integrity reasons.

    I do sometimes use Char(8) or char(12) values as the primary key for short lookup tables such as "status codes", "type codes", "priority codes", etc.  But even there, I have had occassions when I wished I had used an integer

    In any event I would always recommend that you use a short fixed length data type.  Definitely do not use long varchar or GUID values.  Rememeber the Primary key value is copied into every index.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply