Various data types may vary depending on the programming language and more. However, for this post, we will focus on the Bit data type available in SQL Server.”
SQL Server Bit Type
The bit data type is an integer data type that accepts three values; 0, 1, and NULL. The following is the syntax of the BIT type.
SQL Server will automatically optimize the size of columns that store bit data type. For example, if there are eight or fewer bits in a column, SQL Server will store them as 1 byte. If the number of bits is eight or higher, it will store them as 2 bytes.
It is good to remember that Boolean values can be converted to bit types with TRUE resolving to 1 and FALSE resolving to 0.
Example
The following illustrates a create table statement with a bit data type column.
id INT NOT NULL IDENTITY PRIMARY KEY,
bit_data bit
);
You can then insert sample data into the table as:
INTO
TEMP_TABLE(BIT_DATA)
VALUES (0),
(1),
(0),
(1),
(0);
Select data from the table:
Output:
--+--------+
1| 0|
2| 1|
3| 0|
4| 1|
5| 0|
Ended
This short post covered the basics of working with the bit type in SQL Server.
Thanks for reading!!
from https://ift.tt/JeECkMW
0 Comments