Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason why I shouldn't use NVARCHAR in Sql Server?

I'm designing a database scheme right now and I figure just to be safe I should use nvarchar for my textual column's datatypes (for unicode support). While I don't expect non-english text I figure it would be better to have support it from the begining just in case.

Is there any reason why I should stick with plain varchar? Performance?

like image 930
mmcdole Avatar asked Feb 16 '09 07:02

mmcdole


People also ask

Should you always use nvarchar?

If you store character data that reflects multiple languages, always use Unicode data types (nchar, nvarchar, and ntext) instead of the non-Unicode data types (char, varchar, and text). Otherwise your sorting will go weird. "Unicode - (nchar, nvarchar, and ntext).

Should I use nvarchar or varchar in SQL Server?

Today's development platforms or their operating systems support the Unicode character set. Therefore, In SQL Server, you should utilize NVARCHAR rather than VARCHAR. If you do use VARCHAR when Unicode support is present, then an encoding inconsistency will arise while communicating with the database.

Why should you choose the nvarchar data type over varchar?

The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.

Does nvarchar waste space?

As such, NVARCHAR(MAX) can take up to twice as much physical disk space as a NVARCHAR(1.. 4000) field with the same text content+ — even when not stored in the LOB. The non-SCSU waste depends on data and language represented.


2 Answers

In today's i18n world, nvarchar makes a lot of sense. varchar might make sense for data that is specified not to be unicode (perhaps you have some system fields that are demanded to be ASCII).

I'd use nvarchar by default for things like names, descriptions, addresses, etc.

varchar is smaller, so there are perhaps some IO savings with varchar over nvarchar (but note that code-page becomes a bigger issue too).

like image 175
Marc Gravell Avatar answered Oct 05 '22 23:10

Marc Gravell


Also, see this question: VARCHAR vs NVARCHAR performance.

Personally, I say stick to varchar (as I answered in this thread). There is a non-trivial performance overhead.

like image 21
gbn Avatar answered Oct 05 '22 23:10

gbn