If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > varchar field as a primary key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-09-05, 22:19
xirurg xirurg is offline
Registered User
 
Join Date: Nov 2005
Posts: 5
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

Thanks,
Reply With Quote
  #2 (permalink)  
Old 11-10-05, 09:29
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On