0% found this document useful (0 votes)
2 views9 pages

10.Ms SQL - Boolean

The document explains the use of Boolean values in MS SQL Server, noting that there is no direct BOOLEAN data type, but the BIT data type can be used instead, where 0 represents FALSE and 1 represents TRUE. It provides examples of declaring, setting, and using BIT variables, as well as creating a table with a BIT column and inserting data into it. Additionally, it emphasizes best practices for setting Boolean values using 1 and 0 instead of 'true' and 'false'.

Uploaded by

ramsrivalli93
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

10.Ms SQL - Boolean

The document explains the use of Boolean values in MS SQL Server, noting that there is no direct BOOLEAN data type, but the BIT data type can be used instead, where 0 represents FALSE and 1 represents TRUE. It provides examples of declaring, setting, and using BIT variables, as well as creating a table with a BIT column and inserting data into it. Additionally, it emphasizes best practices for setting Boolean values using 1 and 0 instead of 'true' and 'false'.

Uploaded by

ramsrivalli93
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MS SQL - BOOLEAN

[Link] KUMAR B.E.,MBA(HRM) 1


MS SQL - BOOLEAN
• A Boolean is a universal data type which stores true
or false values.
• It is used when we define a variable in a column of the
table.
• In MS SQL Server, there is no direct BOOLEAN data
type.
• Instead, you can use the BIT data type to represent
Boolean values, where 0 represents FALSE and 1
represents TRUE.
• The BIT data type can also accept NULL values.

[Link] KUMAR B.E.,MBA(HRM) 2


Example
declare @myBoolean bit
set @myBoolean='true'
select @myBoolean result

[Link] KUMAR B.E.,MBA(HRM) 3


declare @myBoolean bit
set @myBoolean='false'
select @myBoolean result

[Link] KUMAR B.E.,MBA(HRM) 4


Boolean variable to 1 instead of a true
value. This is a best practice.
declare @myBoolean bit
set @myBoolean=1
select @myBoolean result

[Link] KUMAR B.E.,MBA(HRM) 5


For a false value, you will set the value to 0.
declare @myBoolean bit
set @myBoolean=0
select @myBoolean result

[Link] KUMAR B.E.,MBA(HRM) 6


Set the myBoolean bit variable to null.
declare @myBoolean bit
set @myBoolean=NULL
select @myBoolean result

[Link] KUMAR B.E.,MBA(HRM) 7


How to create a table with a bit data type column

create table myBooleanTable


(
id int,
ispair bit
)
select * from myBooleanTable

[Link] KUMAR B.E.,MBA(HRM) 8


How to insert data with SQL Boolean data type
insert into myBooleanTable values
(1,0),
(2,1),
(5,NULL)

select * from myBooleanTable

[Link] KUMAR B.E.,MBA(HRM) 9

You might also like