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?
2条答案
按热度按时间pes8fvy91#
There should be no differences between the two queries. If there are no
NULL
values present, then obviously any value which is zero is also the same thing as not being one. If there areNULL
s present, it doesn't change anything, because aNULL
record would not be returned from either query.See the demo below.
Demo
9rbhqvlz2#
There should be no difference, because a bit only takes on the values of 0 and 1.
Both will exclude
NULL
values.