一。创建表
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);
2.创建Course表
mysql> create table Course(Cno int primary key not null,Cname varchar(20) not null);
3.创建SC表
mysql> create table SC(Sno int not null,Cno varchar(10) primary key not null,Score int not null);
二。表结构修改
1.修改Student表中年龄(sage)字段属性,字段类型由int改为smallint
mysql> alter table Student change Sage Sage smallint;
2.为Cource表中的Cno课程号设置索引,并进行查看
mysql> create index cno_index on Course(Cno);
3.为SC表建立学号和课程号组合的升序的主键索引,索引名为SCINDEX
create index SCINDEX on SC(Sno ASC,Cno ASC);
4.创建一个视图stu_info,查询全体学生的姓名,性别,课程号,成绩
mysql> create or replace 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.删除所有索引
mysql> drop index cno_index on Course;
mysql> drop index SCINDEX on SC;