Using Binary Data

Accessing and Changing Relational Data

Accessing and Changing Relational Data

Using Binary Data

The binary and varbinary data types store strings of bits. Although character data is interpreted based on the Microsoft® SQL Server™ 2000 code page, binary and varbinary data is simply a stream of bits. binary and varbinary data can be a maximum of 8,000 bytes.

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)

See Also

Binary Data

Data Types