SQL Data Types BINARY and VARBINARY

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Binary data types of either fixed length or variable length.

Syntax:

BINARY [ ( n_bytes ) ]
VARBINARY [ ( n_bytes | max ) ]

n_bytes can be any number from 1 to 8000 bytes. max indicates that the maximum storage space is 2^31-1.

Examples:

SELECT CAST(12345 AS BINARY(10)) -- 0x00000000000000003039
SELECT CAST(12345 AS VARBINARY(10)) -- 0x00003039


Got any SQL Question?