In SQL Server 2005 and 2008 R2, I'm calling into a stored procedure that has an out parameter defined as varbinary(max)
. The out parameter returns 10020 bytes according to DATALENGTH
.
However, SQL Server errors if I try to define a varbinary with> 8000 bytes such as varbinary(10000). E.g.
The size (10000) given to the type 'varbinary' exceeds the maximum allowed for any data type (8000).
What is happening here? How can SQL Server return more bytes than allowed in the data type? Is SQL Server using some other data type behind the scenes to hold> 8000 bytes?
1 Answer 1
The maximum size you can specify is 8000. Anything larger needs to be specified as (MAX)
See https://msdn.microsoft.com/en-us/library/ms188362.aspx for details.
-
Thanks Max. varbinary(max) means you want the possibility of data extending across more than one page. Any size number you set is a size within one page.Concrete Gannet– Concrete Gannet2016年10月14日 05:29:38 +00:00Commented Oct 14, 2016 at 5:29
Explore related questions
See similar questions with these tags.
varbinary(max)
or avarbinary(8000)
but you can't define avarbinary
with a size between 8000 and max (2^31 - 1). Avarbinary(max)
can have a 10,000 byte value, avarbinary(8000)
cannot.