在SQL Server数据库中,我们经常使用索引来提高查询的效率,但是假如索引使用不当就会适得其反。本文我们介绍一种测试索引的空间换时间的操作,以方便找到适合利用索引的时机,接下来就让我们一起来了解一下这部分内容吧。
create table tb_test( t_id number, t_name nvarchar2(30) ); create sequence seq_tid start with 1 increment by 1 maxvalue 999999 minvalue 1 cache 10
--项该表中插入99999条记录
begin for n in 1..99999 loop insert into tb_test values(seq_tid.nextval,'1234'); end loop; end; --select count(*) from tb_test; --select * from tb_test; --select * from tb_test where t_id = 99999;
--此处以下为测试代码,分别在创建索引和没有创建索引的情况下运行。
--你会发现创建索引后后运行的时间比没有创建索引所需要的时间少很多。
declare num number; begin for n in 1..9999 loop select t_id into num from tb_test where t_id=n; end loop; dbms_output.put_line('nunm='||num); end;
--创建对应的索引suncs_space 为自己创建的一个表空间。
create index testid on tb_test(t_id) tablespace suncs_space;
--删除索引
drop index testid;
关于SQL Server数据库测试索引的空间换时间的操作就介绍到这里了,希望本次的介绍能够对您有所帮助。