April 30, 2002 at 3:14 pm
Hello everyone! I've read the FAQ section and I think it's really good but I couln't find an answer to this:
When should I use char and when should I use varchar? This is what they say on MSDN:
Use char when the data values in a column are expected to be consistently close to the same size.
Use varchar when the data values in a column are expected to vary considerably in size.
Well, what is "close to the same size" and what is considered "vary considerably"? I came across this problem when I was making the field "UserName". I want the max size to be 32 but I think almost every Username will be 8 to 12 characters. So they vary over 20 characters from the max size. Is this "vary considerably"?
My first post here. Gimme a good impression
Edited by - tomiz on 04/30/2002 3:15:23 PM
April 30, 2002 at 5:02 pm
I would say yes. Typically I only use chars for small columns that are either null or fill the column..state abbreviations, things like that. The additional overhead for a varchar isn't severe and I believe the combination of the space efficiency and the ease of working with them make varchars the better choice. In my opinion only of course!
Andy
April 30, 2002 at 6:23 pm
To piggy-back on what Andy has already said... varchar saves you space, char performs "slightly" better. Is that slight performance increase noticeable? Probably not for most uses.
The overhead is 2 bytes per varchar column. Pretty small when characters are varying by up to 20 characters. A great article talking a little more about page size and page usage:
http://www.sqlservercentral.com/columnists/sjones/pagesize.asp
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
April 30, 2002 at 8:02 pm
And to add in there. If you do not use the size of the column with a char it will add in blanks after and may require trimming in some apps to get things right (Crystal Reports drove me nuts with this).
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
May 1, 2002 at 6:41 am
Thank you!!
Now I got this staight
Thanks again! I really appreciate it!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply