create nonclustered index fj_index
on aabb(id)--id 是自增列update aabb set Name='wjj' where id=1  --这个能用到索引
 
select * from aabb where id=2  --这个不行为什么select用不到索引,而update确能用到索引?

解决方案 »

  1.   

    参考一下这个
    http://blog.csdn.net/navy887/archive/2009/10/09/4644579.aspx
      

  2.   

    ID是什么类型,不可能是int吧,或者就是ID为2的,在表里面太多太多了,还不如不用索引,直接表扫描呢!
    你要不执行这个看看,select id from aabb where id=2,应该能用起来索引吧!
      

  3.   

    select id from aabb where id=2 确实用了索引,为什么?
      

  4.   

    select id from aabb where id=2 --返回列在索引中,直接用索引就可以找到了
    select * from aabb where id=2 --返回这一行的列,通过你的那个索引应该不能直接定位到,所以才采用了表扫描,这应该是优化器的作用