55

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.

1 Answer 1

75

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.

Sign up to request clarification or add additional context in comments.

1 Comment

in your last sentence, do you mean the behavior of image is the same as varbinary(max) that are over 8k bytes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.