Is it just that nvarchar
supports multibyte characters? If that is the case, is there really any point, other than storage concerns, to using varchars
?
Sql-server – the difference between varchar and nvarchar
nvarcharsql servervarchar
Related Topic
- Sql – Are there any disadvantages to always using nvarchar(MAX)
- Sql-server – the difference between char, nchar, varchar, and nvarchar in SQL Server
- Sql – Difference between JOIN and INNER JOIN
- Sql-server – the difference between Integrated Security = True and Integrated Security = SSPI
- Sql-server – What do Clustered and Non-Clustered index actually mean
- MySQL: Large VARCHAR vs. TEXT
- Postgresql – Difference between text and varchar (character varying)
Best Answer
An
nvarchar
column can store any Unicode data. Avarchar
column is restricted to an 8-bit codepage. Some people think thatvarchar
should be used because it takes up less space. I believe this is not the correct answer. Codepage incompatabilities are a pain, and Unicode is the cure for codepage problems. With cheap disk and memory nowadays, there is really no reason to waste time mucking around with code pages anymore.All modern operating systems and development platforms use Unicode internally. By using
nvarchar
rather thanvarchar
, you can avoid doing encoding conversions every time you read from or write to the database. Conversions take time, and are prone to errors. And recovery from conversion errors is a non-trivial problem.If you are interfacing with an application that uses only ASCII, I would still recommend using Unicode in the database. The OS and database collation algorithms will work better with Unicode. Unicode avoids conversion problems when interfacing with other systems. And you will be preparing for the future. And you can always validate that your data is restricted to 7-bit ASCII for whatever legacy system you're having to maintain, even while enjoying some of the benefits of full Unicode storage.