学生表:Student (Sno, Sname, Ssex , Sage, Sdept)
学号,姓名,性别,年龄,所在系 Sno为主键
create table student(
Sno int auto_increment primary key,
Sname varchar(100) unique not null,
Ssex enum('男','女') not null,
Sage int,
Sdept varchar(100) default '计算机'
);
课程表:Course (Cno, Cname,)
课程号,课程名 Cno为主键
create table Course(
Cno int not null primary key,
Cname varchar(100) not null
);
学生选课表:SC (Sno, Cno, Score)
学号,课程号,成绩 Sno,Cno为主键
create table SC(
Sno int not null,
Cno int not null,
Score int,
primary key (Sno,Cno),
foreign key (Sno) references Student(Sno),
foreign key (Cno) references Course(Cno)
);
create table student(
Sno int auto_increment primary key,
Sname varchar(100) unique not null,
Ssex enum('男','女') not null,
Sage int,
Sdept varchar(100) default '计算机'
);
alter table student modify column Sage smallint;
create index SC_INDEX on SC(Sno,Cno);
CREATE VIEW stu_info AS
SELECT
s.Sname AS Student_Name,
s.Ssex AS Gender,
c.Cname AS Course_Name,sc.Score
FROM student s
JOIN
SC sc ON s.Sno = sc.Sno
JOIN
Course c ON sc.Cno = c.Cno;