木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2010-04-20 👁 5461 👍 0 💬 0 🔄 来源:本站原创
本文所有示例均在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)

暂无评论。

验证码
评论需审核通过后显示
← 上一篇 淘宝店铺所在地区修改 下一篇 → 使用ClientID获取服务器端控件在客户端的ID