sql server 創(chuàng)建索引的意義

sql server 創(chuàng)建索引的意義

ID:34725795

大?。?84.18 KB

頁數(shù):12頁

時間:2019-03-10

sql server 創(chuàng)建索引的意義_第1頁
sql server 創(chuàng)建索引的意義_第2頁
sql server 創(chuàng)建索引的意義_第3頁
sql server 創(chuàng)建索引的意義_第4頁
sql server 創(chuàng)建索引的意義_第5頁
資源描述:

《sql server 創(chuàng)建索引的意義》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫

1、索引工作的意義題目:理解索引的工作意義:創(chuàng)建一個成績表,在成績表中插入幾萬條記錄,嘗試執(zhí)行某個關(guān)于筆試成績的查詢,計算出執(zhí)行該查詢的執(zhí)行時間;然后在筆試(字段)建立索引后,再執(zhí)行相同的查詢,比較這兩次(索引建立前后的執(zhí)行時間)來理解索引創(chuàng)建的意義,將中間的執(zhí)行過程,你的思路、截圖?一,前期準備CREATEDATABASEStudentGOUSEStudentGO--創(chuàng)建成績表createtablestu_grade(stu_idintIDENTITY(1,1)PRIMARYKEY,written_scoreintnotnull,lab_scoreint

2、notnull)go--創(chuàng)建記錄數(shù)據(jù)錄入所需時間表createtabledata_insert_time(markintidentity(1,1),datavolumeint,recrementint,Time_msint,Time_ssfloat)go--創(chuàng)建維護索引所需時間表createtablemaintain_index_time(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat)go--創(chuàng)建記錄未創(chuàng)建索引查詢所需時間表createtablequery_time_unindex

3、(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat,Resultint)go--創(chuàng)建記錄創(chuàng)建索引后查詢所需時間表createtablequery_time_index(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat,Resultint)go--創(chuàng)建插入數(shù)據(jù)的存儲過程,并計算插入數(shù)據(jù)所需時間,同時記錄所需插入時間--分別創(chuàng)建下列存儲過程--createprocproc_insert_40000每插入40000--cre

4、ateprocproc_insert_200000每插入200000--createprocproc_insert_1000000每插入1000000gocreateprocproc_insert_1000000asDECLARE@countint,@accountint,@start_timedatetime,@end_timedatetimeselect@count=0,@start_time=getdate()while(@count<1000000)begininsertintostu_grade(written_score,lab_score

5、)values(floor(100*rand()),floor(100*rand()))set@count=@count+1endselect@end_time=getdate(),@account=(selectcount(stu_id)fromstu_grade)insertintodata_insert_time(datavolume,recrement,Time_ms,Time_ss)values(@account,@count,datediff(ms,@start_time,@end_time),round(convert(float,dat

6、ediff(ms,@start_time,@end_time))/1000,4))go--創(chuàng)建未建索引時所需查詢時間的存儲過程,并獲取所需查詢時間記錄新表gocreateprocproc_query_time_unindexasdeclare@start_timedatetime,@end_timedatetime,@countint,@resultintset@start_time=getdate()select*fromstu_gradewhere(written_scorebetween80and90)andlab_score>90set@res

7、ult=@@rowcountselect@end_time=getdate(),@count=(selectcount(stu_id)fromstu_grade)insertintoquery_time_unindex(datavolume,Time_ms,Time_ss,Result)values(@count,datediff(ms,@start_time,@end_time),round(convert(float,datediff(ms,@start_time,@end_time))/1000,4),@result)go--創(chuàng)建創(chuàng)建索引器的存儲

8、過程,并將創(chuàng)建索引器所需的時間記錄新gocreateprocproc_create_index

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當(dāng)前文檔最多預(yù)覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學(xué)公式或PPT動畫的文件,查看預(yù)覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負責(zé)整理代發(fā)布。如果您對本文檔版權(quán)有爭議請及時聯(lián)系客服。
3. 下載前請仔細閱讀文檔內(nèi)容,確認文檔內(nèi)容符合您的需求后進行下載,若出現(xiàn)內(nèi)容與標題不符可向本站投訴處理。
4. 下載文檔時可能由于網(wǎng)絡(luò)波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯(lián)系客服處理。