Search code examples
sqlsql-servert-sqlbit

TSQL BIT =0 and <>1


Are there any differences if I write

select * from table where bit_field = 0

or

select * from table where bit_field <> 1

?

UPDATE: I've got a report that it is better to use "bit_field = 0" version because if you have some indexes on a field an use the second option there is some issue with "Seek Predicates"... It has two seek predicates one with < 1 and other with > 1... or something. I don't have any example to show. :( After the change from <> to =, there is a decrease of exclusive locks (X) and intent exclusive locks (IX) Any thoughts on that?


Solution

  • There should be no difference, because a bit only takes on the values of 0 and 1.

    Both will exclude NULL values.