/*一、创建索引*/
/*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;
/*二、更新和删除数据*/