Link to home
Start Free TrialLog in
Avatar of kknieriem
kknieriem

asked on

char vs. vchar?

What is the difference between the char and vchar field format and is there a maximum number of characters for either?
ASKER CERTIFIED SOLUTION
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adwiseman
adwiseman

the max for both is 8000 characters

VARCHAR stands for variable length char.  This means that SQL server does not store the entire defined field.  If a field is defined as 8000 characters, and it is only populated with 10 characters, it will only store those 10 characters.  Also, varchar fields trim off any spaces off the end of a string before storing.

ADW
Slight correction: varchar fields require two bytes to store the length, not one bit.  There is also a row overhead of at least two bytes (or something like that) per row if any variable length column is used in a row.  Of course you will still save a lot of space with a VARCHAR(100) vs. a CHAR(100) if you usually don't store 100 bytes.  But, note that it makes no sense to define a VARCHAR(1) or VARCHAR(2) (or even VARCHAR(3)), although I've seen people do it; you will save space and very slightly improve performance be using CHAR(1) or CHAR(2) (or CHAR(3)).
kknieriem:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.