实验八 索引操作

一.实验目的:

掌握索引的创建、查看与删除

二.实验内容:(第1题写到实验报告中)

1.使用T-SQL语句完成下列操作。

1)为stuinfo库中的student表创建按sname列升序的非聚集索引。

   2)为stuinfo库中的Course表创建按Cname列降序的唯一非聚集索引。

3)为stuinfo库中的score表创建一个先按cno升序,再按Degree降序的非聚集索引。

4)为stuinfo库中的score表创建sno和cno列的唯一聚集索引,要求插入或修改时忽略重复键值。

5)调用存储过程sp_helpindex查看score表的索引信息。

6)为OrderManagement库中的customer表创建按客户名升序的非聚集索引。

7)为OrderManagement库中的order_list表创建先按客户名升序,客户名一样的再按订单号升序的唯一非聚集索引,并要求插入或修改时忽略重复键值。

8)为OrderManagement库中的order_detail表创建先按器件号升序,器件号一样再按单价降序的索引。

9)删除上面创建的索引。

2.使用图形界面重新创建第1题中的索引,然后使用图形界面查看这些索引。

create nonclustered index index1

on student(sno,ssex,sclass,sbirthday,sname ASC)

---2

create unique nonclustered index index2

on course(cno,tno,cname DESC)

---3

create nonclustered index index3

on score(sno,cno ASC,degree DESC)

---4

create unique clustered index index4

on score(sno,cno)

with ignore_dum_key

---5

exec sp_helpindex score

--6)为OrderManagement库中的customer表创建按客户名升序的非聚集索引。

use OrderManagement

create nonclustered index index6 on customer(客户名 asc)

--7)为OrderManagement库中的order_list表创建先按客户名升序,客户名一样的再按订单号升序的唯一非聚集索引,并要求插入或修改时忽略重复键值。

create unique nonclustered index index7 on order_list(客户号 asc, 订单号 asc) with ignore_dup_key

--8)为OrderManagement库中的order_detail表创建先按器件号升序,器件号一样再按单价降序的索引。

create index index8 on order_detail(器件号 asc, 单价 desc)

--9)删除上面创建的索引。

drop index student.index1

drop index Course.index2

drop index score.index3

drop index score.index4

drop index customer.index6

drop index order_list.index7

drop index order_detail.index8

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 花了3天时间学习MySql,考了个二级MySql 书籍参考:高等教育出版社《全国计算机等级考试二级教程-MySQL...
    如果仲有听日阅读 5,084评论 4 4
  • MYSQL 基础知识 1 MySQL数据库概要 2 简单MySQL环境 3 数据的存储和获取 4 MySQL基本操...
    Kingtester阅读 12,375评论 5 116
  • 观其大纲 page 01 基础知识 1 MySQL数据库概要 2 简单MySQL环境 3 数据的存储和获取 4 M...
    周少言阅读 8,347评论 0 33
  • 1).创建数据库 create database学生选课数据库 2).创建四张表 Create table Stu...
    blvftigd阅读 5,534评论 0 0
  • 天空与海其实是一样的 到了与云比肩的地方 到了浮出水面的地方 一团团的云 是浮在海面上的棉絮 远方的天际线 是海与...
    周登禹阅读 2,224评论 0 4

友情链接更多精彩内容