我应该使用什么SQL Server数据类型来存储一个字节[]

时间:2022-09-15 19:11:52

I want to store an array of bytes in my SQL Server. What datatype, or pre INSERT manipulation would you suggest to store these?

我想在SQL服务器中存储一个字节数组。您建议存储哪些数据类型或预插入操作?

I wouldn't expect these byte[] to exceed 1024 in length.

我不希望这些字节[]的长度超过1024。

1 个解决方案

#1


49  

varbinary(1024) is what you're looking for.

varbinary(1024)是您需要的。

There are three types in SQL Server for binary value storage:

SQL Server中有三种类型的二进制值存储:

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.

二进制(n)用于长度为n的定长二进制数据。长度可为1至8000。可变长度二进制数据最大长度n的varbinary(n)。最大长度可以是1到8000。上述类型将存储在行数据本身中。varbinary(max),用于存储最多2GB的大二进制值。如果实际值大于8000字节,并且只在行中存储一个指针,那么实际值将存储在一个单独的位置。这种类型可以从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.

在SQL Server 2005之前,使用图像数据类型来存储BLOBs。不赞成使用varbinary(max)。图像的存储位置总是在数据行之外。

#1


49  

varbinary(1024) is what you're looking for.

varbinary(1024)是您需要的。

There are three types in SQL Server for binary value storage:

SQL Server中有三种类型的二进制值存储:

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.

二进制(n)用于长度为n的定长二进制数据。长度可为1至8000。可变长度二进制数据最大长度n的varbinary(n)。最大长度可以是1到8000。上述类型将存储在行数据本身中。varbinary(max),用于存储最多2GB的大二进制值。如果实际值大于8000字节,并且只在行中存储一个指针,那么实际值将存储在一个单独的位置。这种类型可以从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.

在SQL Server 2005之前,使用图像数据类型来存储BLOBs。不赞成使用varbinary(max)。图像的存储位置总是在数据行之外。