目录
1 实验内容
2 SQL代码
3 效果截图
1 实验内容
熟悉SQL实验环境配置和进行实验数据准备,用SQL Server、PostgreSQL或MySQL创建数据库,
并按照下列关系模式定义数据表,加入适当约束:
学生(学号、姓名、性别、年龄、系名)
课程(课程号、课程名、先修课程、学分)
学生选课(学号、课程号、成绩)
2 SQL代码
create table Student
(
Sno char(12) primary key,
Sname varchar(20) not null,
Ssex char(2) not null,
constraint s2 check(Ssex in('男', '女')),
Sage int not null,
constraint s3 check (Sage between 0 and 130),
Department varchar(20) not null
);
create table Course
(
Cno char(12) primary key,
Cname varchar(20) not null,
Cprepare varchar(20) not null,
Ccredit float not null,
constraint c3 check(0 < Ccredit)
);
create table SC
(
Sno char(12) not null,
Cno char(12) not null,
Performance float not null,
constraint sc1 check(Performance between 0 and 100),
foreign key(Sno) references Student(Sno),
foreign key(Cno) references Course(Cno)
);