22,209
社区成员
发帖
与我相关
我的任务
分享
create database "选课系统" ;
--系(系号)
create table Department
(
Dept char(20) primary key
);
--学生(学号,姓名,性别,年龄,系别)
create table Student
(
Sno char(9) primary key,
Sname char(20) not null,
Ssex char(2) check(Ssex in ('男','女')),
Sage smallint check(Sage>=0 and Sage <= 150 ),
Dept char(20),
--constraint c1 check(Sage>=0 and Sage <= 150 ),
foreign key Dept references Department(Dept)
) ;
--课程(课程号,课程名,开课系,任课教师)
create table Course
(
Cno smallint primary key,
Cname char(20) not null,
Dept char(20) ,
Cteacher char(20) ,
foreign key Dept references Department(Dept)
);
--学习(学号,课程号,成绩)
create table SC
(
Sno char(9) not null,
Cno smallint not null,
Grade smallint check(Grade <=100 and Grade >=0),
primary key (Sno,Cno),
foreign key Sno references Student(Sno),
foreign key Cno references Course(Cno)
);
create table Department
(
Dept char(20) primary key
);
go
--学生(学号,姓名,性别,年龄,系别)
create table Student
(
Sno char(9) primary key,
Sname char(20) not null,
Ssex char(2) check(Ssex in ('男','女')),
Sage smallint check(Sage>=0 and Sage <= 150 ),
Dept char(20),
--constraint c1 check(Sage>=0 and Sage <= 150 ),
foreign key (Dept) references Department(Dept)
) ;
go
--课程(课程号,课程名,开课系,任课教师)
create table Course
(
Cno smallint primary key,
Cname char(20) not null,
Dept char(20) ,
Cteacher char(20) ,
foreign key (Dept) references Department(Dept)
);
go
--学习(学号,课程号,成绩)
create table SC
(
Sno char(9) not null,
Cno smallint not null,
Grade smallint check(Grade <=100 and Grade >=0),
primary key (Sno,Cno),
foreign key (Sno) references Student(Sno),
foreign key (Cno) references Course(Cno)
);
go
create database 选课系统
--系(系号)
create table Department
(
Dept char(20) primary key
);
go
--学生(学号,姓名,性别,年龄,系别)
create table Student
(
Sno char(9) primary key,
Sname char(20) not null,
Ssex char(2) check(Ssex in ('男','女')),
Sage smallint check(Sage>=0 and Sage <= 150 ),
Dept char(20),
--constraint c1 check(Sage>=0 and Sage <= 150 ),
foreign key references Department(Dept)
)
;
--课程(课程号,课程名,开课系,任课教师)
create table Course
(
Cno smallint primary key,
Cname char(20) not null,
Dept char(20) ,
Cteacher char(20) ,
foreign key references Department(Dept)
);
--学习(学号,课程号,成绩)
create table SC
(
Sno char(9) not null,
Cno smallint not null,
Grade smallint check(Grade <=100 and Grade >=0),
primary key (Sno,Cno),
foreign key references Student(Sno),
foreign key references Course(Cno)
);