select * from syscolumns where id in(select id from sysobjects)
select * from syscolumns a where exists(select id from sysobjects where id=a.id)
在查询分析器中,查看以上两句的执行计划,两个的执行成本各占50%,完全一样。
而且执行的步骤也完全相同,截图奉上。
大侠们能给解释一下吗?

解决方案 »

  1.   

    select * from 大表 where cc in (小表)
    select * from 小表 where exists(大表)表A(小表),表B(大表)1:select * from A where cc in (select cc from B) 
           效率低,用到了A表上cc列的索引;
       select * from A where exists(select cc from B where cc=A.cc) 
           效率高,用到了B表上cc列的索引。select * from table where id in('1','2')select * from table t where exists(select id from table where id=t.id) 
    你数据量不够大
      

  2.   

    执行步骤是一样的,加上not就不一样了
      

  3.   

    参考:
    http://www.cnblogs.com/haibin168/archive/2011/02/20/1959170.html数据量较小的时候,一般差距不明显。
      

  4.   

    exists和in的执行效率,大部分情况下是一样的.