SQL Server數(shù)據(jù)庫測試索引的空間換時間
作者:shunshun20520
本文我們主要介紹了SQL Server數(shù)據(jù)庫測試索引的空間換時間的操作,并給出了詳細(xì)的實例代碼,希望能夠?qū)δ兴鶐椭?/div>
在SQL Server數(shù)據(jù)庫中,我們經(jīng)常使用索引來提高查詢的效率,但是如果索引使用不當(dāng)就會適得其反。本文我們介紹一種測試索引的空間換時間的操作,以方便找到適合利用索引的時機,接下來就讓我們一起來了解一下這部分內(nèi)容吧。
- 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;
--此處以下為測試代碼,分別在創(chuàng)建索引和沒有創(chuàng)建索引的情況下運行。
--你會發(fā)現(xiàn)創(chuàng)建索引后后運行的時間比沒有創(chuàng)建索引所需要的時間少很多。
- 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;
--創(chuàng)建對應(yīng)的索引suncs_space 為自己創(chuàng)建的一個表空間。
- create index testid on tb_test(t_id) tablespace suncs_space;
--刪除索引
- drop index testid;
關(guān)于SQL Server數(shù)據(jù)庫測試索引的空間換時間的操作就介紹到這里了,希望本次的介紹能夠?qū)δ兴鶐椭?/p>
【編輯推薦】
責(zé)任編輯:趙鵬
來源:
CSDN博客


相關(guān)推薦




