BIT is a standard SQL data type representing fixed-length sequences of bits (0 or 1). Depending on the dialect, BIT can store a single Boolean value or a bit array of length n. When declared without a length, most engines default to 1 bit. Storage is highly compact: SQL Server stores up to 8 BIT columns in 1 byte, while MySQL and PostgreSQL pack bits into bytes as needed. Comparing BIT to BOOLEAN: ANSI SQL defines BOOLEAN separately, but many databases map BOOLEAN to BIT(1) behind the scenes (SQL Server) or support both (PostgreSQL). BIT values are manipulated with binary literals (B'1', 0b0101), numeric literals (0 or 1), or bitwise operators (&, |, ^) depending on the dialect. Caveats: BIT is not portable in DDL or literals across systems, some dialects silently pad or truncate bit strings, and NULL is distinct from 0. Indexing BIT(1) columns offers limited selectivity, so composite indexes or alternative types may be preferred.
n
(integer) - Optional. Number of bits to store. Must be a positive integer.SQL-92 standard; early vendor support in SQL Server 6.0
BIT is ideal for compact storage or packing several flags into one column. BOOLEAN offers clearer semantics for a single true or false value but is internally mapped to BIT(1) in some engines.
If you omit the length, most databases create a 1-bit column, effectively storing a Boolean value.
Use dialect-specific syntax: B'1010' in PostgreSQL, 0b1010 in MySQL, or simply 0 and 1 in SQL Server, which automatically casts integers to BIT.
The keyword exists across major systems, but literal formats, maximum lengths, and casting behaviors differ. Always validate when migrating schemas.