Click to See Complete Forum and Search --> : I'd like to know


ViVeg
November 22nd, 2007, 08:53 AM
Hello everybody!
I'd like to know what is really difference between Char and Varchar?

andreasblixt
November 22nd, 2007, 09:09 AM
A char will always take up the specified length, while a varchar will only take up the length of its value. I.e.:

A char(10) value set to 'Hello' will become 'Hello ' (five spaces in the end; 10 characters in total.)

A varchar(10) value will remain as 'Hello'.

hspc
November 23rd, 2007, 06:54 AM
In addition, SQL server stores extra data (2 bytes long as i remember) to determine the length of varchar and nvarchar data types.
In general to optimize both storage and data retrieval time, if your data does not exceed 10 characters, you should use char, if data will exceed 20 characters you should use varchar.