3

I want to store the string including Unicode character.

I know there are two choices. NVARCHAR and VARCHAR. NVARCHAR uses 2 bytes to store a character; however VARCHAR uses 1 byte for a character.

In terms of storing 2 2-byte unicode character each of them uses 4 bytes. But when it comes to storing 1 1-byte ansi character and 1 2-byte unicode character, NVARCHAR uses 4 bytes, and VARCHAR uses 3 bytes.

So I think using VARCHAR is more compact and always be the better method. I don't know if my understand above is right or not because there should be some advances that NVARCHAR is over VARCHAR.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Marcus Thornton
  • 5,955
  • 7
  • 48
  • 50
  • AFAIK , NVARCHAR only will help you when you use a different collate and need to sort this information according . – ceinmart Apr 19 '13 at 12:28

1 Answers1

2

Smaller => faster. But beware of indexes and the type of data you present it *1. And beware of the different datatypes in different types of database servers *2

*1) In MSSQL: When you have an index over a VARCHAR column and present it a Unicode String, MSSQL-Server does not make use of the index. The same thing happens when you present a BigInt to a indexed-column containing SmallInt. Even if the BigInt is small enough to be a SmallInt, SQL-Server is not able to use the index. The other way around you do not have this problem (when providing SmallInt or Ansi-Code to an indexed BigInt ot NVARCHAR column).

*2) Know that every database has slightly different datatypes and VARCHAR does not means the same everywhere. While MSSQL has VARCHAR and NVARCHAR, an Apache/Derby database has only VARCHAR and there VARCHAR is in Unicode.

incomudro
  • 548
  • 4
  • 12