This question is related to my SQL Data type size
A varchar(max)
seems to be able to store up to 2GB.
What I can not understand though is that in this link sql row overflow MS says (my emphasis):
A table can contain a maximum of 8,060 bytes per row. In SQL Server 2008, this restriction is relaxed for tables that contain varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns. The length of each one of these columns must still fall within the limit of 8,000 bytes; however, their combined widths can exceed the 8,060-byte limit. This applies to varchar, nvarchar, varbinary, sql_variant, or CLR user-defined type columns when they are created and modified, and also to when data is updated or inserted.
I don't understand this statement.
They say that a varchar(max)
can hold up to 2GB but then they say in the above link that the column length can not be more than 8KB
Isn't this contradictory or am I missing something here?
To make things clear, we could take the first statement which is a very fundamental one:
In other words: each row must fit into one page (8 kB). And if possible, many rows can fit into one page - but never the other way round.
How about binary large objects (TEXT, NTEXT, BLOB)? Data in these columns is stored in a special place. The row just holds a pointer to the data, hence the fundamental statement above still holds: a table row must fit into one page.
Having this said, the new varchar(max) feature is special and behaves as follows:
Note the big data content depends on all the other columns of the table. Furthermore, varchar(max) can store text in compressed form such that more than 8,060 characters might fit into one data page.
In my opinion, the statement The length of each one of these columns must still fall within the limit of 8,000 bytes seems not to be precise, possibly even incorrect (a varchar(max) column can in fact hold 2 GB of data, though not being stored in row).