sql server 创建索引的意义

sql server 创建索引的意义

ID:34725795

大小:284.18 KB

页数:12页

时间:2019-03-10

sql server 创建索引的意义_第1页
sql server 创建索引的意义_第2页
sql server 创建索引的意义_第3页
sql server 创建索引的意义_第4页
sql server 创建索引的意义_第5页
资源描述:

《sql server 创建索引的意义》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、索引工作的意义题目:理解索引的工作意义:创建一个成绩表,在成绩表中插入几万条记录,尝试执行某个关于笔试成绩的查询,计算出执行该查询的执行时间;然后在笔试(字段)建立索引后,再执行相同的查询,比较这两次(索引建立前后的执行时间)来理解索引创建的意义,将中间的执行过程,你的思路、截图?一,前期准备CREATEDATABASEStudentGOUSEStudentGO--创建成绩表createtablestu_grade(stu_idintIDENTITY(1,1)PRIMARYKEY,written_scoreintnotnull,lab_scoreint

2、notnull)go--创建记录数据录入所需时间表createtabledata_insert_time(markintidentity(1,1),datavolumeint,recrementint,Time_msint,Time_ssfloat)go--创建维护索引所需时间表createtablemaintain_index_time(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat)go--创建记录未创建索引查询所需时间表createtablequery_time_unindex

3、(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat,Resultint)go--创建记录创建索引后查询所需时间表createtablequery_time_index(markintidentity(1,1),datavolumeint,Time_msint,Time_ssfloat,Resultint)go--创建插入数据的存储过程,并计算插入数据所需时间,同时记录所需插入时间--分别创建下列存储过程--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--创建未建索引时所需查询时间的存储过程,并获取所需查询时间记录新表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--创建创建索引器的存储

8、过程,并将创建索引器所需的时间记录新gocreateprocproc_create_index

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。