How to insert value in the BIT column in SQL Server?
In SQL Server, BIT is a datatype that can take a value of 0, 1, or NULL.
SQL Server optimize storage for BIT columns by allocating 1 byte of storage for each batch of 8 BIT columns. If a table has up to 8 BIT columns, the columns are stored as 1 byte, if there are more than 8 and up to 16 BIT columns, SQL Server stores the BIT columns as 2 bytes, and so on.
To create a table with BIT column:
CREATE TABLE table_name (
bit_column BIT
);
To insert a new value to the BIT column, use INSERT statement:
INSERT INTO table_name (bit_column)
VALUES (1);
You can also use TRUE and FALSE as the inputs for the BIT columns, SQL Server will automatically convert them as follow:
- TRUE will be converted to 1
- FALSE will be converted to 0
SQL Server also converts any nonzero values to BIT value 1.
Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS