Search content within the blog

Wednesday, April 22, 2009

Difference between varchar and nvarchar in sqlserver

VarChar is a variable length string of ASCII characters.
NVarChar is a variable length string of UNICODE characters.

ASCII characters each take one Byte of space.
UNICODE characters each take Two Bytes of space.

NVarChar is truncate the whitespce but not in VarChar.

For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables. Other languages have an extended set of character codes that need to be saved and this datatype allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages.

In principle they are the same and are handled the same by your application. The only difference is that NVARCHAR can handle unicode characters allowing you to use multiple languages in the database. NVARCHAR takes twice as much space to store to allow for the extended character set required by some other languages. So if you are not using other languages then definitley use VARCHAR for character data.

No comments:

Post a Comment