I need to know the maximum number of characters I can put into a varchar(max) or text field using Sql Server. In this page I have found that the maximum number of bytes for storage is 2GB (2^31 - 1). Since I suppose, according to this page and other I've searched, the Unicode character is 2 byte sized, I conclude that I have to divide the total byte size for the Unicode character size, which does not give an integer result. Any sugestions where I am failing? Why does the page say the maximum string length is 2^31 - 1 instead of 2^31?
Asked
Active
Viewed 478 times
0
-
I think you are confusing varchar(max) with nvarhar(max). varchar(max) has one byte per character – Rob Mar 21 '14 at 18:04
-
http://stackoverflow.com/questions/1761124/how-many-characters-in-varcharmax Without going into detail it depends on character encoding being used. http://www.unicode.org/faq/utf_bom.html or http://stackoverflow.com/questions/4270049/what-is-the-maximum-number-of-characters-that-nvarcharmax-will-hold – xQbert Mar 21 '14 at 18:04
-
Yes, Rob, I am confusing. Varchar is NON-Unicode. I thought it was Unicode. And xQbert, the first link was very useful. Thanks. The answer, by the way, is 2^31-3 characters (for varchar). – mhkgalvez Mar 21 '14 at 18:47
1 Answers
0
From SQL Server 2012 Help:
Variable-length, non-Unicode string data. ndefines the string length and can be a value from 1 through 8,000. maxindicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes. The ISO synonyms for varcharare char varyingor character varying.

user2063329
- 443
- 2
- 5
- 15