Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005

    Question varchar field as a primary key

    Hello All

    Could someone explain to me please what are the advantages and disadvantages to have varchar field (username in my case) as PRIMARY KEY


  2. #2
    Join Date
    Mar 2004
    Toronto, ON, Canada
    Shouldn't make much of a difference from a design standpoint.

    At the implementation level, there could be some performance differences. Depends on the RDBMS, different software handles it different ways.

    I'm most familiar with DB2. VARCHAR has an extra 2 bytes for length, so if most of your columns are the same length, CHAR saves space. VARCHAR also can lead to some space management issues, since an UPDATE can increase the space a column needs. This can require more processing than an in-place update. There also used to be some issues with DB2 and comparissons, where it wouldn't use your index if the data types didn't exactly match. No longer the case.

    But with today's systems unless your database has absolutely critical performance requirements, I doubt you'll see much difference.
    Jonathan Petruk
    DB2 Database Consultant

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts