What SQL Server Datatype Should I Use To Store A Byte[]
I want to store an array of bytes in my SQL Server. What datatype, or pre INSERT manipulation would you suggest to store these?
I wouldn't expect these byte[]
to exceed 1024 in length.
Solution 1:
varbinary(1024)
is what you're looking for.
There are three types in SQL Server for binary value storage:
binary(n)
for fixed-length binary data of length n
. Length can be 1
to 8000
.varbinary(n)
for variable-length binary data maximum length n
. Maximum length can be 1
to 8000
.
Above types will be stored in the row data itself.
varbinary(max)
which is used to store large binary values (BLOBs) up to 2GB. The actual value is stored in a separate location if it's larger than 8000 bytes and just a pointer is stored in the row itself. This type is available since SQL Server 2005.
image
data type was used to store BLOBs prior to SQL Server 2005. It's deprecated in favor of varbinary(max)
. The storage location for image
is always outside data row.