通过SQL Server2000执行计划查看索引的使用情况

本文所有示例均在Student表上操作,表结构如下:

Create TABLE [dbo].[Student] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [name] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
    [age] [int] NULL
)

在Student表上建如下索引:



例1:select * from student



例2:select * from student where id<5



例3:select * from student where name like 'zhang%'



例4:select * from student where age>=18



例5:select * from student where name like 'zhang%' and age>=18



例6:select * from student where name like 'zhang%' and age>=18 and id<10



例7:select * from student where name like '%zhang%'



总结

·创建有用的索引很重要,它能大大提高查询的效率,如例2~例6;
·创建有效的查询语句很重要,它能保证尽可能的使用到索引[1],例7和例3就是最好的例子;

[1].要让查询尽可能使用到索引,就应在查询中尽量避免使用否定运算符,例如NOT、!=、<>、!>、!<、NOT EXISTS、NOT IN和NOT LIKE,避免对字段使用函数,例如:
引用内容 引用内容
name like '%zhang%'
age<>15
abs(age)>=18


评论: 0 | 引用: 0 | 查看次数: 4681
发表评论
登录后再发表评论!