Pages

Thursday 23 August 2012

Difference between Char, Varchar and Nvarchar in SQL?


Char DataType
Char datatype is used to store fixed length data. For example if we declared char(100) then it allocate memory for 100 characters, No matter how many length characters we insert/saved in it. Example : if we declare char(100) and insert/save only 10 characters of word then only 10 characters of memory will be used and other 90 characters of memory will be wasted.

Varchar DataType
Varchar, the name suggests itself that variable length characters. It is used to store non-unicode characters. It will allocate the memory based on number of characters inserted. Suppose if we declared varchar(100) it will allocates memory of 0 characters at the time of declaration. If we insert only 10 characters of word, it will allocate memory for only 10 characters.

Nvarchar DataType
Nvarchar datatype same as varchar datatype but only difference nvarchar is used to store Unicode characters and it allows you to store multiple languages in database. So when you are going to create bilingual or multi-language website then nvarchar is used.  




No comments:

Post a Comment