Welcome to SqlServer-QA.net Sign in | Join | Help

SQL Server Storage Engine & Tools (SSQA.net)

SQL Server Tools includes storage engine that includes a complete set of graphical tools and command prompt utilities that allow users, programmers, and administrators. SSMS, SSRS, SSIS & SSAS are most commonly used tools.
What is the difference between having a char vs varchar column as part of a primary key?

As it sounds this is an interview question, but if you look at the logical level of nothing much changes.

There are two major concerns using such way, Performance and Storage space. In this using fixed char fields can be queried faster than varchar fields. But there is a relative difference in fetching the results using with CHAR vs VARCHAR. Only the difference you will find is the occupation of data using char as differed to varchar as Char is stored as a fixed length string, Varchar is stored as a variable length.

IMHO either of them are a best candidate for PRIMARY key at all. 

Coming to the data VARCHAR is better to program and handle the data that you don't have idea, but need to take care of extra spaces on the data while presentation.  In the real sens for the size, I suggest to char instead of varchar only if it is less than 10 chars. The overhead of a varchar isn't worth it if it is less than 10, but is definitely worth it before you reach 50!  For instance few columns of type char(50) with only 10-30 chars in them waste a lot of space. Over a couple thousand (or hundreds of thousands) rows, that is a lot of hollow space in the database, which is not good.

Posted: Thursday, August 16, 2007 1:11 AM by SQL Master

Comments

Other SQL Server Blogs around the Web said:

As it sounds this is an interview question, but if you look at the logical level of nothing much changes

# August 16, 2007 1:31 AM

SSQA.net - SqlServer-QA.net said:

As it sounds this is an interview question, but if you look at the logical level of nothing much changes

# August 16, 2007 3:38 AM
Anonymous comments are disabled