/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2014/11/23 2:03:17 */
/*==============================================================*/
drop table if exists Class;
drop table if exists Course;
drop table if exists Student;
drop table if exists 选课;
/*==============================================================*/
/* Table: Class */
/*==============================================================*/
create table Class
(
班级号 char(4) not null,
Sno char(12),
班级名 varchar(20),
primary key (班级号)
);
/*==============================================================*/
/* Table: Course */
/*==============================================================*/
create table Course
(
Cno char(4) not null,
Cname char(10),
Ccredit int,
Cpno char(4),
primary key (Cno)
);
/*==============================================================*/
/* Table: Student */
/*==============================================================*/
create table Student
(
Sno char(12) not null,
班级号 char(4),
Sname varchar(10) not null,
Ssex char(2),
Sage int,
primary key (Sno)
);
/*==============================================================*/
/* Table: 选课 */
/*==============================================================*/
create table 选课
(
Cno char(4) not null,
Sno char(12) not null,
成绩 int,
primary key (Cno, Sno)
);
alter table Class add constraint FK_任班长 foreign key (Sno)
references Student (Sno) on delete restrict on update restrict;
alter table Student add constraint FK_属于 foreign key (班级号)
references Class (班级号) on delete restrict on update restrict;
alter table 选课 add constraint FK_选课 foreign key (Cno)
references Course (Cno) on delete restrict on update restrict;
alter table 选课 add constraint FK_选课2 foreign key (Sno)
references Student (Sno) on delete restrict on update restrict;