美文网首页
实验八 索引操作

实验八 索引操作

作者: LANVNAL | 来源:发表于2018-12-17 22:01 被阅读0次

    一.实验目的:

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

    二.实验内容:(第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

    相关文章

      网友评论

          本文标题:实验八 索引操作

          本文链接:https://www.haomeiwen.com/subject/gxjhkqtx.html