Export (0) Print
Expand All
3 out of 8 rated this helpful - Rate this topic

Using Binary Data

The binary and varbinary data types store strings of bits. Although character data is interpreted based on the SQL Server code page, binary and varbinary data is simply a stream of bits.

binary data can store a maximum of 8,000 bytes. varbinary, using the max specifier, can store a maximum of 2^31 bytes. For more information about varbinary(max), see Using Large-Value Data Types

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.

The following Transact-SQL example stores a SID and hexadecimal literal:

USE AdventureWorks2008R2;
GO
CREATE TABLE MyCcustomerTable
(
    user_login   varbinary(85) DEFAULT SUSER_SID()
    ,data_value   varbinary(1)
);
GO

INSERT MyCustomerTable (data_value)
    VALUES (0x4F);
GO
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.