Hello everybody!
I'd like to know what is really difference between Char and Varchar?
Printable View
Hello everybody!
I'd like to know what is really difference between Char and Varchar?
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(five spaces in the end; 10 characters in total.)Code:'Hello '
A varchar(10) value will remain as 'Hello'.
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.