Transact-SQL Reference


SQL Server 2008 Books Online (October 2009)
bit (Transact-SQL)

An integer data type that can take a value of 1, 0, or NULL.

Remarks

The SQL Server Database Engine optimizes storage of bit columns. If there are 8 or less bit columns in a table, the columns are stored as 1 byte. If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on.

The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0.

See Also

Reference

ALTER TABLE (Transact-SQL)
CAST and CONVERT (Transact-SQL)
CREATE TABLE (Transact-SQL)
Data Types (Transact-SQL)
DECLARE @local_variable (Transact-SQL)
DELETE (Transact-SQL)
INSERT (Transact-SQL)
SET @local_variable (Transact-SQL)
sys.syscolumns (Transact-SQL)
UPDATE (Transact-SQL)

Other Resources

Data Type Conversion (Database Engine)

Help and Information

Getting SQL Server 2008 Assistance
Tags :


Community Content

Thomas Lee
is / is not

Often C/C# programmers (including me) fall into the trap and believe that IS NOT operator can be used to query if a bit column is true (1) or false (0):

is MyTable.ABitColumn
is not MyTable.ABitColumn
MyTable.ABitColumn is true
MyTable.ABitColumn is false


but we have to to that following:

MyTable.ABitColumn = 1 -- is true
MyTable.ABitColumn = 0 -- is false


So, is not operator can only be used to ask if a column is null or not and there exists no true / false constant in SQL?

Tags : sql

Pleasant Holiday
storage for 8 columns of type bit??
This page says that
(1) bit fields can be 1, 0 or NULL (three values) and
(2) eight such fields will be stored in one byte.

That's got to be wrong. Or am I missing something?
Tags : contentbug

Page view tracker