Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Varchar(max) and nvarchar(max) [duplicate]

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.

like image 452
selva Avatar asked Jun 16 '15 06:06

selva


People also ask

Should you use VARCHAR or nvarchar?

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.

When should I use nvarchar Max?

Use varchar when the sizes of the column data entries vary considerably. Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.

What is the max of nvarchar Max?

nvarchar [ ( n | max ) ] n defines the string size in byte-pairs, and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^30-1 characters (2 GB).

Is VARCHAR 8000 the same as VARCHAR Max?

About varchar(MAX)If your data is longer than 8000 characters varchar(MAX) is what you need. You can store up to 2GB size of data this way. In varchar(MAX) fields if your data size is shorter than 8000 characters your data is stored in row automatically (therefore the data execution is faster).


2 Answers

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

like image 56
marc_s Avatar answered Oct 15 '22 17:10

marc_s


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.

like image 2
Mukesh Kalgude Avatar answered Oct 15 '22 17:10

Mukesh Kalgude