最初由 javadiannet 发布
[B]drop table tbl_stu_for_index
create table tbl_stu_for_index
(
stu_id varchar(20),
stu_name varchar(20),
stu_sex bit,
stu_score decimal(10,1)
)
declare @a datetime
declare @b datetime
declare @i int
set @a=getdate()
select ceiling(rand()*100)
set @i = 0
while(@i<200000)
begin
insert into tbl_stu_for_index(stu_id,stu_score)
values(@i,ceiling(rand()*100))
set @i=@i+1
end
set @b=getdate()
select datediff(ms,@a,@b)
====
上述代码建表,并插入20万条数据
declare @a datetime
declare @b datetime
declare @i int
set @a=getdate()
select * from tbl_stu_for_index(index =ix_stu_for_index_stu_id)where stu_id=100100
set @b=getdate()
select datediff(ms,@a,@b)
====
上述代码测试没有索引时查询时间,多次查询结果3000毫秒
create index ix_stu_for_index_stu_id
on tbl_stu_for_index(stu_id)
===
建立索引
declare @a datetime
declare @b datetime
declare @i int
set @a=getdate()
select * from tbl_stu_for_index(index =ix_stu_for_index_stu_id)where stu_id=100100
set @b=getdate()
select datediff(ms,@a,@b)
======
使用索引查询时间,依然显示在 3000毫秒 [/B]
呵呵,你有没有注意字段类型呢。。。
你明明在表中定义的stu_id字段的类型为varchar(20),查询时却用。。。
这样索引当然失效了。
你把查询条件改为stu_id='100100'试试。
|