实验八 索引操作

版权声明:喜欢就点个赞吧,有啥疑问可以留言交流~ https://blog.csdn.net/m0_38015368/article/details/84986615

实验八 索引操作

一.实验目的:

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

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

1 使用T-SQL语句完成下列操作。
1)为stuinfo库中的student表创建按sname列升序的非聚集索引。

use stuinfo
create index ix_sname on student(sname)

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

create unique nonclustered index ix_cname on Course(Cname) 

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

create nonclustered index ix_score on score(cno asc, degree desc)

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

create unique clustered index ix_score_2 on score(cno, degree) with ignore_dup_key

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

sp_helpindex score


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

use OrderManagement
create nonclustered index ix_customer on customer(客户号 asc)


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

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


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

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

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

use stuinfo
drop index ix_sname on student
drop index ix_cname on Course
drop index ix_score on score
drop index ix_score_2 on score

use OrderManagement
drop index ix_customer on customer
drop index ix_order_list on order_list
drop index ix_order_detail on order_detail 

猜你喜欢

转载自blog.csdn.net/m0_38015368/article/details/84986615