From this Microsoft doc,+
n defines the string length and can be a value from 1 through 8,000.
max indicates 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.
Please help me understand this.
The max characters for varchar seems to be 8000
, which is way less than 2GB
worth of data.
I see that there are records in this varchar(max)
column of a specific table that have len(mycolumn)
> 100 000.
Thus I know I can get way more than 8000
characters into a varchar(max)
column.
Question 1: How does the 8000
characters come into play and where should I be aware of it?
Question 2 : will a .net datareader query to this column always return the full result with 100 000+ character?
Best Answer
I can see why you're misunderstanding this - it's a little tricky. These are all valid:
And yes, if you try to get data out of a VARCHAR(MAX) field, and somebody stored 2GB in there, buckle up.