Pages

Wednesday, November 11, 2009

Varchar vs Nvarchar

VARCHAR is stored as regular 8-bit data. But NVARCHAR strings are stored in the database as UTF-16 — 16 bits or two bytes per character. So Nvarchar takes up more space. Max for nvarchar is 4000 unlike varchar which is 8000.

Nvarchar is for unicode strings and varchar for non-unicode strings.
Unicode (nvarchar) has the capability to store characters from all
languages, while varchar typically uses a local code page and can only use
local characters. So If you have customers from around the world, it is suggested to use NVARCHAR.

One of the biggest uses found for nvarchar is in importing data.
Loading text fields is a problem because people put strange things in the
fields. Importing into a nvarchar almost always gets the data in while
varchar often has issues with things like NPC's. Once in you can just
change the data type to varchar if you want and everything is fine.

No comments:

Post a Comment