I have declared a column of type NVARCHAR(MAX)
in SQL Server 2008, what would be its exact maximum characters having the MAX as the length?

- 732,580
- 175
- 1,330
- 1,459

- 3,409
- 7
- 23
- 30
4 Answers
The max size for a column of type NVARCHAR(MAX)
is 2 GByte of storage.
Since NVARCHAR
uses 2 bytes per character, that's approx. 1 billion characters.
Leo Tolstoj's War and Peace is a 1'440 page book, containing about 600'000 words - so that might be 6 million characters - well rounded up. So you could stick about 166 copies of the entire War and Peace book into each NVARCHAR(MAX)
column.
Is that enough space for your needs? :-)

- 732,580
- 175
- 1,330
- 1,459
-
35Just a nit pick. NVARCHAR uses 2 bytes for most characters. For unicode caracters over U+00FFFF. It'll use four bytes. – Eli Algranti Jul 28 '15 at 05:15
-
3Nitpicking: "The storage size is two times n bytes + 2 bytes." ([Source](https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-ver15#arguments)) – RobIII Jun 25 '21 at 13:02
-
3"A common misconception is to think that NCHAR(n) and NVARCHAR(n), the n defines the number of characters. But in NCHAR(n) and NVARCHAR(n) the n defines the string length in **byte-pairs**" ([Source])(https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-ver15#remarks) – RobIII Jun 25 '21 at 13:10
By default, nvarchar(MAX) values are stored exactly the same as nvarchar(4000) values would be, unless the actual length exceed 4000 characters; in that case, the in-row data is replaced by a pointer to one or more seperate pages where the data is stored.
If you anticipate data possibly exceeding 4000 character, nvarchar(MAX) is definitely the recommended choice.
-
13It is also NOT recomended if your data will never exceed 4000 characters as there are indexing issues. – HLGEM Jun 21 '12 at 13:46
-
-
Hi @FabioMilheiro , can I ask which part is outdated. Is that the pointer storage part? – Xu Shaoyang Feb 04 '22 at 23:16
From MSDN Documentation
nvarchar [ ( n | max ) ]
Variable-length Unicode string data. 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
I think actually nvarchar(MAX)
can store approximately 1070000000 chars.

- 10,349
- 9
- 44
- 84

- 127
- 1
- 2
-
Can you explain where you're getting that number, and what you mean by "accurately"? (i.e. are you saying that's not a hard limit, but with more characters there can be problems? What kinds of problems? Why?) – Adi Inbar Nov 26 '14 at 23:22
-
7I am not sure, but I think, if nvarchar uses double space than varchar to store a char , and the maximun number of memory that can be used by nvarchar(MAX) to store chars is 2^31-1 => 2147483647, then 2147483647/2 is 1073741824. by accurately I mean that is not an exact number. – Francisco Javier Larios Soto Nov 27 '14 at 16:50