北邮大三数据库实验六数据查询分析实验.docxVIP

北邮大三数据库实验六数据查询分析实验.docx

  1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
北邮大三数据库实验六数据查询分析实验

实验六数据查询分析实验实验目的通过对不同情况下查询语句的执行分析,巩固和加深对查询和查询优化相关理论知识的理解,提高优化数据库系统的实践能力,熟悉了解Sybase中查询分析器的使用,并进一步提高编写复杂查询的SQL 程序的能力。实验内容1.索引对查询的影响(1)对结果集只有一个元组的查询分三种情况进行执行(必如查询一个具体学生的信息):不建立索引,(学号上)建立非聚集索引,(学号上)建立聚集索引。建立聚集索引:createclusteredindex studenton student(student_id)go建立非聚集索引:createnonclusteredindex student_indexon student(student_id)go用查询分析器的执行步骤和结果对执行进行分析比较。select*from student where student_id=30201不建立索引建立聚集索引建立非聚集索引(2)对结果集中有多个元组的查询(例如查看某门成绩的成绩表)分类似(1)的三种情况进行执行比较。select*from student where student_id30401不建立索引:建立聚集索引:建立非聚集索引:(3)对查询条件为一个连续的范围的查询(例如查看学号在某个范围内的学生的选课情况)分类似(1)的三种情况进行执行比较,注意系统处理的选择。select*from student where student_id between31201and31415不建立索引:建立聚集索引:建立非聚集索引:(4)索引代价。在有索引和无索引的情况下插入数据(例如在选课情况表SC 上插入数据),比较插入的执行效率。insertinto student values(31710,张攀,男,1993-1-1 00:00:00,计算机,3146)deletefrom student where student_id =31710无索引:建立聚集索引:建立非聚集索引:2、对相同查询功能不同查询语句的执行比较分析group byselectavg(score)from scgroupby course_idhaving course_id=C01selectavg(score)from scwhere course_id=C01比较其查询效率可知,没有group by的查询时间比较短,查询效率较高(2)select student_id,student_name,birthdayfrom student s1wherebirthday=(selectmax(birthday)from student s2where s1.department = s2.department)另一个:select department,max(birthday)as maxAge into tmpfrom studentgroupby department;select student_id,student_name,birthdayfrom student,tmpwhere student.birthday = tmp.maxAge and tmp.department=student.departmentdroptable tmp查询结果来看,重写的执行时间要快一些,但相差不多,如果数据库比较大的话,执行效果也许更明显(3)对下面两个查询进行比较select student_name,birthdayfrom studentwhere department!=电信and birthdayall(select birthdayfrom studentwhere department =电信)另:select student_name,birthdayfrom studentwhere department!=电信and birthday(selectmax(birthday)from studentwhere department =电信)3、查询优化除了建立适当索引,对SQL 语句重写外,还有其他手段来进行查询调优,例如调整缓冲区大小,事先建立视图等。设计实现下列查询,使之运行效率最高。写出你的查询形式,以及调优过程;并说明最优情况下的运行时间。查找选修了每一门课的学生。方法一:with student1(num,account)as(selectdistinct student_id,count(course_id)from scgroupby student_id)select student_namefrom student1,studentwhere student1.account=5 and student1.num=student

文档评论(0)

haihang2017 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档