mysql建立学号与课程编号的索引_Mysql学习四

/*一、创建索引*/

/*1、为学生成绩表在建立学号和课程编号上的唯一索引

唯一索引指的是此处的每一个索引值只对应唯一的数据记录

*/

create unique index stu_sco_index

on v_student_score(student_id,course_id);

/*2、运行结果可通过执行系统的存储过程查看:Sp_helpindex 表名*/

/*Sql Server运行代码*/

Sp_helpindex v_student_score;

/*Mysql运行代码*/

show index

from v_student_score;

/*3、为教材选用表在数量上建立聚集索引聚簇索引指索引项的顺序与表中记录的物理顺序一致*/

/*Sql server运行代码*/

/*①默认情况下,主键是聚集索引。先删除系统默认创建的索引PK__v_textbook_selec__2A4B4B5E*/

alter table v_textbook_selection

drop constraint PK__v_textbook_selec__2A4B4B5E;

/*②添加主键,将表中规定主键修改为非聚集类型*/

alter table v_textbook_selection

add constraint pk_course_textbook

primary key nonclustered(course_id, textbook_id) ;

/*③在数量列上创建此聚集索引*/

create clustered index textbook_selection_index

on v_textbook_selection(textbook_selection_number);

/*④查看索引,查看到一条是sql server默认给主键设置的索引,另一条便是第③步创建的聚集索引*/

Sp_helpindex v_textbook_selection;

/*Mysql运行代码*/

/*①为Mysql建立一个普通索引*/

create index textbook_selection_index

on v_textbook_selection(textbook_selection_number);

/*②查看索引*/

show index

from v_textbook_selection;

/*4、删除教材选用表在数量上的索引*/

/*Sql Server运行代码*/

drop index textbook_selection_index

on v_textbook_selection;

Sp_helpindex v_textbook_selection;

/*Mysql运行代码*/

alter table v_textbook_selection

drop index textbook_selection_index;

show index

from v_textbook_selection;

/*二、更新和删除数据*/

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值