测试T-SQL中的不等式 [英] Testing for inequality in T-SQL
本文介绍了测试T-SQL中的不等式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在WHERE子句中遇到过这个问题:
I've just come across this in a WHERE clause:
AND NOT (t.id = @id)
与此相比如何:
AND t.id != @id
或者用:
AND t.id <> @id
我自己总是写下后者,但显然别人有不同的想法。一个人会比另一个更好吗?我知道使用<>
或!=
将会破坏我使用索引的希望已经有,但肯定上面的第一种方法会遇到同样的问题吗?
I'd always write the latter myself, but clearly someone else thinks differently. Is one going to perform any better than the other? I know that using <>
or !=
is going to bust any hopes for using an index that I might have had, but surely the first approach above will suffer the same problem?
推荐答案
这3个将会获得相同的执行计划
These 3 will get the same exact execution plan
declare @id varchar(40)
select @id = '172-32-1176'
select * from authors
where au_id <> @id
select * from authors
where au_id != @id
select * from authors
where not (au_id = @id)
当然,它还取决于索引本身的选择性。我总是使用au_id<> @id我自己
It will also depend on the selectivity of the index itself of course. I always use au_id <> @id myself
这篇关于测试T-SQL中的不等式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文