CREATE DATABASE stusys;
USE stusys;
CREATE TABLE student
(
sno VARCHAR(6) NOT NULL PRIMARY KEY COMMENT'学号',
sname VARCHAR(8) NOT NULL COMMENT'姓名',
ssex VARCHAR(2) NOT NULL DEFAULT '男' COMMENT'性别',
sbirthday DATE NOT NULL COMMENT'出生日期',
speciality VARCHAR(12) NULL COMMENT'专业',
tc TINYINT NULL COMMENT'总学分'
);
DESC student;
INSERT INTO student
VALUES
('191001','刘清泉','男','1998-06-21','计算机','52'),
('191002','张慧玲','女','1999-11-07','计算机','50'),
('191003','冯涛','男','1999-08-12','计算机','52'),
('196001','董明霞','女','1999-05-02','通信','50'),
('196002','李茜','女','1998-07-25','通信','48'),
('196004','周俊文','男','1998-03-10','通信','52');
SELECT * FROM student;
CREATE TABLE course
(
cno VARCHAR(4) NOT NULL PRIMARY KEY COMMENT'课程号',
cname VARCHAR(16) NOT NULL COMMENT'课程名',
credit TINYINT NULL COMMENT'学分'
);
DESC course;
INSERT INTO course
VALUES
('1004','数据库系统','4'),
('1017','操作系统','3'),
('4002','数字电路','3'),
('8001','高等数学','4'),
('1201','英语','4');
SELECT * FROM course;
CREATE TABLE score
(
sno VARCHAR(6) NOT NULL COMMENT'学号',
cno VARCHAR(4) NOT NULL COMMENT'课程号',
garde TINYINT NULL COMMENT'成绩',
PRIMARY KEY(sno,cno)
);
DESC score;
INSERT INTO score
VALUES
('191001','1004','95'),
('191002','1004','87'),
('191003','1004','93'),
('196001','4002','90'),
('196002','4002','79'),
('196004','4002','88'),
('191001','8001','92'),
('191002','8001','88'),
('191003','8001','84'),
('196001','8001','87'),
('196002','8001',NULL),
('196004','8001','94'),
('191001','1201','92'),
('191002','1201','78'),
('191003','1201','93'),
('196001','1201','84'),
('196002','1201','76'),
('196004','1201','92');
SELECT * FROM score;
CREATE TABLE teacher
(
tno CHAR(6) NOT NULL PRIMARY KEY COMMENT'教师编号',
tname CHAR(8) NOT NULL COMMENT'姓名',
tsex CHAR(2) NOT NULL DEFAULT '男' COMMENT'性别',
tbirthday DATE NOT NULL COMMENT'出生日期',
title CHAR(12) NULL COMMENT'职称',
school CHAR(12) NULL COMMENT'学院'
);
DESC teacher;
INSERT INTO teacher
VALUES
('100006','何艺杰','男','1970-06-23','教授','计算机学院'),
('100023','孙浩然','男','1979-04-09','教授','计算机学院'),
('400017','李亚兰','女','1988-11-04','讲师','通信学院'),
('800028','袁万明','男','1978-08-15','副教授','数学学院'),
('120045','刘颖','女','1976-12-15','副教授','外国语学院');
SELECT * FROM teacher;
CREATE TABLE lecture
(
tno CHAR(6) NOT NULL COMMENT'教师编号',
cno CHAR(4) NOT NULL COMMENT'课程号',
location CHAR(10) NULL COMMENT'上课地点',
PRIMARY KEY(tno,cno)
)COMMENT'讲座';
DESC lecture;
INSERT INTO lecture
VALUES
('100006','1004','2-311'),
('400017','4002','1-106'),
('800028','8001','6-104'),
('120046','1201','6-215');
SELECT*FROM lecture;