SQL Server Binary Data Types

Binary Data Types

Binary data types in SQL Server represent sequences of bytes. They are used to store non-textual information, such as images, audio files, and other binary files. These data types are used when you need to store raw data instead of text-based representations.

Supported Binary Data Types

Using VARBINARY

The VARBINARY data type is the most common and recommended way to store binary data in SQL Server. It is a variable-length data type, meaning it can store different amounts of binary data depending on the values stored within it.

CREATE TABLE MyTable ( ID INT PRIMARY KEY, ImageData VARBINARY(MAX) );

Example

The following example demonstrates how to insert a binary value into a VARBINARY column.

INSERT INTO MyTable (ID, ImageData) VALUES (1, 'This is binary data');