Number of Characters in SQL Server varchar(max)? -


microsoft's documentation on varchar(max) data type:

"variable-length, non-unicode string data. . . max indicates maximum storage size 2^31-1 bytes (2 gb). storage size actual length of data entered + 2 bytes"

http://technet.microsoft.com/en-us/library/ms176089.aspx

i thought 2^31 bytes = 2 gb, not 2^31-1 bytes = 2 gb. wrong on point?

two of bytes reserved column overhead, question becomes:

how many characters data type store?
a) 2^31-3 = 2,147,483,645 bytes = 2,147,483,645 characters
b) 2^31-2 = 2,147,483,646 bytes = 2,147,483,646 characters

the number 2^31-1 0x7fffffff in hex. it's largest possible positive 32-bit number on twos-compliment machine (like x86 , else).

the documentation telling maximum storage size, has hold length of data plus 2 bytes. means maximum data size 2^31-1-2, or 2,147,483,645 (0x7ffffffd).


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -