1. 修改 student 表中年龄( sage )字段属性,数据类型由 int 改变为 smallint :
ALTER TABLE student MODIFY Sage SMALLINT;
2. 为 Course 表中 Cno 课程号字段设置索引,并查看索引:
ALTER TABLE Course ADD INDEX idx_Cno (Cno);
SHOW INDEX FROM Course;
3. 为 SC 表建立按学号( sno )和课程号( cno )组合的升序的主键索引,索引名为 SC_INDEX :
ALTER TABLE sc ADD PRIMARY KEY SC_INDEX (sno, Cno);
4. 创建一视图 stu_info ,查询全体学生的姓名,性别,课程名,成绩:
CREATE VIEW stu_info AS
SELECT s.Sname, s.Ssex, c.Cname, sc.Score
FROM student s
JOIN sc ON s.Sno = sc.Sno
JOIN course c ON sc.Cno = c.Cno;
5. 删除所有索引:
ALTER TABLE Course DROP INDEX idx_Cno;
ALTER TABLE sc DROP PRIMARY KEY SC_INDEX;