Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 NVarchar (MAX) - actual number of characters?

Author  Topic 

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2009-07-02 : 15:16:25
Hello all

i have read several different online articles that have a different value for the maximum number of characters that can be stored in an Nvarchar(MAX) column. Does anyone know the definite answer?
Here is what I have found:
- 536,870,912
- 1,048,576
- 1,073,741,823

Thanks for any help.
- will

TheSQLGuru
SQL Server MVP

10 Posts

Posted - 2009-07-02 : 15:23:50
Anytime you want to know specifics such as this simply use Books Online. They are amazingly helpful!

See here in 2005 BOL: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/81ee5637-ee31-4c4d-96d0-56c26a742354.htm

nvarchar [ ( n | max ) ]
Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The SQL-2003 synonyms for nvarchar are national char varying and national character varying.


Kevin G Boles
TheSQLGuru
Indicium Resources, Inc.
Go to Top of Page

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2009-07-02 : 16:04:59
Thanks. And YES...I did read the BOL. My issue is that it did state something different than other articles.

Since this one states the max number of storage bytes is " 2^31-1 bytes" am I to assume that equates to the maximum number of characters? I thought that because this is unicode it would cut that in half? Or, am I wrong?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-08-04 : 07:12:27
No, you are right.
NVARCHAR can store 1 billion+ characters and takes twice the amount on disk becuase of the two-byte representation.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -