How many characters in varchar(max)

Russell picture Russell · Nov 19, 2009 · Viewed 140.4k times · Source

How many characters can a SQL Server 2008 database field contain when the data type is VARCHAR(MAX)?

Answer

i_am_jorf picture i_am_jorf · Nov 19, 2009

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

varchar [ ( n | max ) ] Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for varchar are char varying or character varying.

1 character = 1 byte. And don't forget 2 bytes for the termination. So, 2^31-3 characters.