SQL SERVER Bit field Data Type
SQL Server bit field data type is used to store Boolean values . i.e true or false.
Note: SQL Server doesn't support Yes or No.
TRUE --> 1
FALSE --> 0
Example 1:
Declare @b bit = 1;
select @b
Example 2;
declare @b bit= cast('true' as bit)
select @b
Example 3:
Create table bdemo([status] bit);
insert into bdemo(1);
insert into bdemo(0);
insert into bdemo(cast('true' as bit));
insert into bdemo(cast('false' as bit));
declare @b char='1';
insert into bdemo values(@b); --implicit conversion from char to bit
insert into bdemo values(@b); --implicit conversion from char to bit
Example 4: Boolean Data Type falls under Number data type.
declare @b bit=false;
select ISNUMERIC(@b)
displays 1
Example 5: Implicit Converting char to bit data type
declare @b char(1) = '1';select ISNUMERIC(@b)
displays 1,
Tags: SQL SERVER Bit field Data Type ,SQL Server boolean Data Types, char to bit field conversion in sql server, inserting into bit field column,
No comments:
Post a Comment