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.
In Sql Server, use image data type or varbinary data type, to store byte array data.
Description: Byte is an immutable value type that represents unsigned integers with values that range from 0 to 255. You can almost convert any kind of data into Byte Array(Byte []) like File, Image, Xml and etc.. In SQL Server, we have enough datatypes to store string text, int, bool, datatime and even Xml.
TEXT is a variable width character string data type that supports non-Unicode data in the code page of a SQL database server and with a maximum string length of 2,147,483,647. This data type is used for storing large pieces of string data values.
Conclusion. As you can see, SQL Server does not include arrays. But we can use table variables, temporary tables or the STRING_SPLIT function. However, the STRING_SPLIT function is new and can be used only on SQL Server 2016 or later versions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With