CREATE TABLE Students(
sno CHAR(10) NOT NULL PRIMARY KEY,
sname VARCHAR(20),
sex CHAR(2),
bdate DATE,
height DECIMAL(5, 2),
department VARCHAR(20)
);
CREATE TABLE Courses(
cno CHAR(10) NOT NULL PRIMARY KEY,
cname VARCHAR(20),
lhour INT,
credit DECIMAL(2, 1),
semester VARCHAR(10)
);
CREATE TABLE SC(
sno CHAR(10) NOT NULL,
cno CHAR(10) NOT NULL,
grade DECIMAL(4, 1),
PRIMARY KEY(sno, cno),
CONSTRAINT fk_sno FOREIGN KEY (sno) REFERENCES Students(sno) ON DELETE CASCADE,
CONSTRAINT fk_cno FOREIGN KEY (cno) REFERENCES Courses(cno) ON DELETE CASCADE
);
INSERT INTO Students VALUES('0102101','张三','男','1988-01-01',1.70,'计算机系');
INSERT INTO Students VALUES('0102105','李四','男','1985-04-01',1.86,'计算机系');
INSERT INTO Students VALUES('0401110','王五','女','1986-02-02',1.65,'电机系');
INSERT INTO Students VALUES('0401111','赵六','男','1987-04-02',1.60,'电机系');
INSERT INTO Courses VALUES('CS-220','编译原理',30,4,'秋季');
INSERT INTO Courses VALUES('CS-221','体系结构',40,2,'秋季');
INSERT INTO Courses VALUES('CS-222','数据库',60,4,'秋季');
INSERT INTO Courses VALUES('EE-110','电子技术',30,4,'秋季');
INSERT INTO Courses VALUES('EE-111','数字逻辑',30,3,'秋季');
INSERT INTO Courses VALUES('EE-112','数字电路',30,4,'秋季');
INSERT INTO SC VALUES('0102101','CS-220',89);
INSERT INTO SC VALUES('0102101','CS-221',90);
INSERT INTO SC VALUES('0102101','CS-222',97);
INSERT INTO SC VALUES('0102105','CS-220',66);
INSERT INTO SC VALUES('0102105','CS-221',70);
INSERT INTO SC VALUES('0102105','CS-222',60);
INSERT INTO SC VALUES('0401110','EE-110',NULL);
INSERT INTO SC VALUES('0401110','EE-111',80);
INSERT INTO SC VALUES('0401110','EE-112',90);
INSERT INTO SC VALUES('0401111','EE-110',90);
INSERT INTO SC VALUES('0401111','EE-111',89);
INSERT INTO SC VALUES('0401111','EE-112',90);