SQL Server Not(A=B and C=D) vs (A<> B or C<> D) -


i have simple performance related question regarding equality , inequality. past experience learnt eq conditions work better , or conditions cause perf issues.

when @ query plan both when executed side side both had scan type of eq

did same query plan. make difference if have query formatted not(a=b , c=d) or work (a <> b or c<> d)

what best approach?

did not think nulls here, here difference.

select 1 not(2=1 , null=2) select 1 not(2=1 , 3=null) select 1 not(2=1 , null=2) select 1 not(1=1 , 3=null) select 1 not(null=1 , 2=2) select 1 not(null=null , 2=2)   --point note one. false, true select 1 not(1=1 , 3=3)  select 1 (2<>1 or null<>2) select 1 (2<>1 or 3<>null) select 1 (2<>1 or null<>2) select 1 (1<>1 or 3<>null) select 1 (null<>1 or 2<>2) select 1 (null<>null or 2=2)      --point note one. true, true select 1 (1<>1 or 3<>3) 

for simple comparisons, expect these have same execution plans. or tends prevent use of indexes. however, unlikely indexes used not-equals.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -