The binary and varbinary data types store strings of bits. Although character data is interpreted based on the Microsoft® SQL Server™ code page, binary and varbinary data is simply a stream of bits. binary and varbinary data can be up to 8,000 bytes long.
Binary constants have a leading 0x (a zero and the lowercase letter x) followed by the hexadecimal representation of the bit pattern. For example, 0x2A specifies the hexadecimal value of 2A, which is equivalent to a decimal value of 42 or a one-byte bit pattern of 00101010.
Use binary data when storing hexadecimal values such as a security identification number (SID), a GUID (using the uniqueidentifier data type), or a complex number that can be stored using hexadecimal shorthand.
This Transact-SQL example stores a SID and hexadecimal literal:
USE pubs
CREATE TABLE mycustomertable
(
user_login DEFAULT SUSER_SID,
data_value
)
INSERT mycustomertable (data_value)
VALUES (0x4F)
Binary Data | Data Types |