Difference between Varchar(max) and nvarchar(max)

47.6k views Asked by At

I came across a question while buidling schema for my application.

When to use varchar(max) and nvarchar(max). I mean the exact use cases where it should be applied. I have surfed in net too but I was able to get the exact answer.

Could anyone suggest some exact usecase.

4

There are 4 answers

3
marc_s On BEST ANSWER

This is for Microsoft SQL Server:

NVARCHAR is Unicode - 2 bytes per character, therefore max. of 1 billion characters; will handle East Asian, Arabic, Hebrew, Cyrillic etc. characters just fine.

VARCHAR is non-Unicode - 1 byte per character, max. capacity is 2 billion characters, but limited to the character set you're SQL Server is using, basically - no support for those languages mentioned before

0
Mukesh Kalgude On

Varchar(max)

Varchar fields can be of any size up to a limit, which varies by databases: an Oracle 9i database has a limit of 4000 bytes, a MySQL database has a limit of 65,535 bytes (for the entire row) and Microsoft SQL Server 2005 has a limit of 8000 characters (unless varchar(max) is used, which has a maximum storage capacity ...

nvarchar(max)

abcdefg n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.

0
Jens On

You should use nvarchar if you have to store unicode char. If you only store non-unicode-char you can use varchar.

0
Hassan Habib On

nvarchar is for unicode data, whilst varchar is uses only up to 8-bit codepage. Use cases: varchar is good when you're dealing with Latin letters in general, so let's say you have a blog and the language used to write to this blog is English, at this case varchar is a good option. nvarchar is good when you're building a multilingual application, so you're using characters like Mandarin, Arabic ..etc.

Hope this helps.