Reputation: 845
I am saving files (any type ) in a SQL table, using a varbinary(max)
, I find out that the max usage of this datatype is 8000, but what does the 8000 mean?
The online documentation says that is 8000 bytes. Does that mean that the maximum size of the file to be save there is 8000/1024 = 7.8125 KB?
I start testing and the maximum file that I can store is 29.9 MB. If I choose a larger file a get a SQLException.
String or binary data would be truncated. The statement has been terminated.
Upvotes: 19
Views: 91382
Reputation: 791
Implement SQL Server 2012 (codename Denali) when it's released - it has FileTable
feature :)
varbinary(8000)
is limited by 8000 bytes - that's for sure!varbinary(max)
is limited by 2 gigabytesvarbinary(max) FILESTREAM
is limited by your file system (FAT32 - 2 Gb, NTFS - 16 exabytes)Upvotes: 53
Reputation: 51
I got the "String or binary data would be truncated" error when trying to store 5MB using varbinary(max) on SQL Server 2005. Increasing the autogrowth size for the database solved the problem. Took me a while to figure out, so just thought I'd share :)
Upvotes: 5
Reputation: 2063
Taken from here:
http://msdn.microsoft.com/en-us/library/ms188362.aspx:
max indicates that the maximum storage size is 2³¹-1 bytes
which is 2 147 483 647 bytes. I'm not sure why it stops at 29.9MB.
Upvotes: 10
Reputation: 4687
What version of SQL Server are you using?
Varbinary on MSDN for SQL Server 2008 explicitly says that VarBinary(MAX) is for use when "the column data entries exceed 8,000 bytes."
Also, I would also take a look at the Filestream Capabilities in SQL Server 2008 if that is the server you are using.
Upvotes: 5