all groups > sql server programming > june 2005 >
You're in the

sql server programming

group:

char vs. varchar


char vs. varchar Paul Pedersen
6/27/2005 5:52:16 PM
sql server programming:
Is there a general rule when to use char and when to use varchar? I'm
talking about short, simple fields, like "last name" etc.

I had thought that varchars would be useful, since I won't need to trim them
after retrieving their values; but instead I have to trim before storing, so
there's no real savings. They take the same amount of storage space, right?

Anyone care to comment on the relative benefits?




Re: char vs. varchar Sylvain Lafontaine
6/27/2005 9:07:02 PM
The difference is between doing the trim one time or an unlimited number of
times and no, they doesn't take the same amount of storage. (With, of
course, the exception that very short fields of 1, 2 or 3 chars may take a
little more space because of the two bytes required to store the length of
the string.)

Excerpt for particular cases where the number of characters is fixed by the
nature of the field, you should always use varchar or nvarchar.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF


[quoted text, click to view]

Re: char vs. varchar Paul Pedersen
6/28/2005 5:39:16 AM
Thank you.


"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
[quoted text, click to view]

AddThis Social Bookmark Button