第7章 使用视图与索引优化查询_第1页
第7章 使用视图与索引优化查询_第2页
第7章 使用视图与索引优化查询_第3页
第7章 使用视图与索引优化查询_第4页
第7章 使用视图与索引优化查询_第5页
已阅读5页,还剩38页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2select 列表名from 表名 , n where 条件例:select * from xsqk where 出生日期75by 学号order by 学号45select 学号, 姓名, 联系电话 from xsqkwhere ( select avg(成绩) from xs_kc where xsqk.学号=xs_kc.学号 ) 60selectfrom where select fromwhere说明说明:子查询执行后子查询执行后,若返回若返回1个单值个单值,则可用则可用比较运算比较运算符符来设置条件来设置条件:若返回一个列表若返回一个列表值值,则可用则可用:(not) in、any

2、、allin6生成一张新表,其中保存的是查询结果的数据789101112 create view v1 as select studentid,studentname,sex,birthday,classid from student where classid=10702select * from v113create view V综合信息 as select student.studentid,studentname,coursename,score from student,course,score where student.studentid=score.studentidand c

3、ourse.courseid=score.courseidwith encryption对视图的定义进行加密对视图的定义进行加密exec sp_helptext v综合信息14create view V平均成绩(学生学号,个人平均分)with encryptionas select studentid, avg (score) from score group by studentid15create view V单科最高分asselect courseid,max(score) from score group by courseid)16create view V全校最高分asselect

4、 student.studentid,studentname,courseid,score from student,scorewhere student.studentid=score.studentid and score= (select max(score) from score)171819alter view v综合信息 as select student.studentid,studentname,coursename,score from student,course,score where student.studentid=score.studentidand course

5、.courseid=score.courseidwith check option20212223242526对于小表来说,是可行的。但对于有成千上万行的表来说,其搜索的效率非常低。建立索引。272829303132333435生成惟一性聚集索引生成惟一性非聚集索引36默认值37create unique indexon( 课程名 desc)with drop_existingcreate indexon( 课程名 desc)删除同名的原索引,重建新索引。38create unique clustered index pk_xs_kcon xs_kc(学号 desc ,课程号)with pad_index, fillfactor=60, drop_existing中间级索引页也按“填充因子”指定的填充度填充

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论