Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 593
divinci Avatar asked Jun 29 '09 14:06

divinci


People also ask

Can you store a byte array in SQL?

In Sql Server, use image data type or varbinary data type, to store byte array data.

What is the data type byte array in SQL Server?

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.

What is text [] in SQL?

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.

Is there an array data type in SQL Server?

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.


1 Answers

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.

like image 156
mmx Avatar answered Sep 21 '22 21:09

mmx