Varchar data type is good candidate for PK | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Varchar data type is good candidate for PK

Hi, i need small inputs from your end to conclude whether to use varchar as primary key or not.To find out the performance difference between varchar and INT.I have create two tables where in one table contains varchar as primary key with 10,000 records and other tables contains additional column as ID(PK) data type as INT(also having 10,000records). I have found not much difference in retrieving the records but i can see the difference in CPU and Cost of I/O. Where CPU and Cost of I/O is more in case table containing varchar as primary key. Please advice me which is the better option. Thanks and Regards
Ravi K
I don’t see any problem using Varchar data type for PK but make sure it is narrow not 100/200 character long.. http://www.sqlmag.com/Articles/Index.cfm?ArticleID=5113
MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

With only 10k rows you’re likely to see no difference anyway. Pump it up to 2.000.000 or more and do some query variations using JOINs, GROUP BYs, WHEREs. I would bet the INT PK will outperform the VARCHAR PK. —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
]]>