Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 1,0,NULL in BIT field?

Author  Topic 

mikeyh
Starting Member

2 Posts

Posted - 2007-06-01 : 09:06:42
I was browsing through our database and I noticed that we had some "NULL" values in a field of type bit, even though it already had 1's and 0's. How is this at all possible?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-01 : 09:12:40
It is because Bit datatype supports three values - 1,0 and NULL and since you made column Nullable, there are bound to be NULL values.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-01 : 09:15:03
Note that BIT datatype will have NULL too if you define it to have NULL values

Declare @b bit
Select @t=NULL
Select @t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mikeyh
Starting Member

2 Posts

Posted - 2007-06-01 : 09:48:44
So does that then also mean that each of those fields takes up 2 bits instead of 1?
Go to Top of Page
   

- Advertisement -