Search Web

Saturday, February 5, 2011

varchar Vs. nvarchar


char, nchar, varchar, and nvarchar each take a length parameter which the database engine can use to optimize storage.

UTF-16 (when sticking to the BMP) has a simple two-to-one relationship between bytes of storage and characters, which the database can take advantage of. 

The amount of storage required for a UTF-8 string of N characters is not as clear, and could result in wasted space, or unexpectedly truncated strings.
varchar does not store ASCII, it stores an 8-bit encoding.

nvarchar and varchar do not "function identically" since varchar does not function at all in lots of scenarios. 

varchar contain max size 8000 while nvarchar size is 4000. 

nvarchar may take up twice as much space, but varchar is twice as slow, since it requires string conversions for every read and write (on those occasions when it actually works).