MySQL-4-视图和索引
一、题目

二、建表
1、建立Student表
mysql> create table Student(-> Sno int primary key auto_increment,-> Sname varchar(30) not null unique ,-> Ssex varchar(2) check (Ssex='男' or Ssex='女') not null,-> Sage int not null,-> Sdept varchar(10) default '计算机' not null);
Query OK, 0 rows affected (0.03 sec)
结果:

2、建立Sc表
mysql> create table Sc(-> Sno int not null,-> Cno varchar(10) primary key not null,-> Score int not null);
Query OK, 0 rows affected (0.01 sec)结果:

3、建立Course表
mysql> create table Course( Cno int primary key not null, Cname varchar(20) not null);结果:

三、查询建立
1.修改student 表中年龄(sage)字段属性,数据类型由int 改变为smallint
mysql> alter table Student modify Sage smallint;结果:

2.为Course表中Cno 课程号字段设置索引,并查看索引
mysql> create index Course_Cno on Course(Cno);结果:

3.为SC表建立按学号(sno)和课程号(cno)组合的升序的主键索引,索引名为SC_INDEX
mysql> create unique index Sc_index on Sc(Sno,Cno);
结果:
mysql> show index from Sc\G;

4.创建一视图 stu _info,查询全体学生的姓名,性别,课程名,成绩
mysql> create view stu_info as select Sname '姓名',Ssex '性别',Cname '课程名',Score '成绩'from Student join Sc on Student.Sno=Sc.Sno join Course on Sc.Cno=Course.Cno;结果:

5.删除所有索引

