MySQL-學生表以及課程、老師、成績表的創建

學生表以及課程、老師、成績表的創建

-- 刪除表
drop table if exists score;
drop table if exists student;
drop table if exists course;
drop table if exists teacher;

學生表

create table student(
	stuNo	char(5) primary key, -- 學生學號
	stuName varchar(32) not null, -- 學生姓名
	gender char(1) not null	default '男', -- 學生性別
	age int not null -- 學生年齡
)charset='utf8';
-- 添加學生數據
insert into student(stuNo,stuName,gender,age) values('001','李志','男',14);
insert into student(stuNo,stuName,gender,age) values('002','宋東野','男',23);
insert into student(stuNo,stuName,gender,age) values('003','趙雷','男',34);
insert into student(stuNo,stuName,gender,age) values('004','馬頔','男',32);
insert into student(stuNo,stuName,gender,age) values('005','陳粒','女',18);
insert into student(stuNo,stuName,gender,age) values('006','筠子','女',4);
insert into student(stuNo,stuName,gender,age) values('007','寸鐵','男',56);
insert into student(stuNo,stuName,gender,age) values('008','狗毛','男',47);
insert into student(stuNo,stuName,gender,age) values('009','崔健','男',39);
insert into student(stuNo,stuName,gender,age) values('010','草東','男',40);
insert into student(stuNo,stuName,gender,age) values('011','張懸','女',36);
insert into student(stuNo,stuName,gender,age) values('012','撒嬌','女',25);
insert into student(stuNo,stuName,gender,age) values('013','宋東野','男',35);

教師表

create table teacher(
	tNo char(5) primary key, -- 教師號
	tName varchar(32) not null -- 教師名字
)charset='utf8';
-- 添加老師數據
insert into teacher(tNo,tName) values('t001','張三');
insert into teacher(tNo,tName) values('t002','李四');
insert into teacher(tNo,tName) values('t003','王二');
insert into teacher(tNo,tName) values('t004','王五');

課程表

create table course(
	cNo char(5) primary key, -- 課程號
	cName varchar(32) not null unique, -- 課程名
	tNo char(5), -- 教師號
	foreign key(tNo) references teacher(tNo)
)charset='utf8';

-- 添加課程數據
insert into course(cNo,cName,tNo) values('c001','數據結構','t001');
insert into course(cNo,cName,tNo) values('c002','操作系統','t002');
insert into course(cNo,cName,tNo) values('c003','計算機網絡','t001');
insert into course(cNo,cName,tNo) values('c004','軟件工程','t003');
insert into course(cNo,cName,tNo) values('c005','計算機組成原理','t002');
insert into course(cNo,cName,tNo) values('c006','數據庫系統','t002');
insert into course(cNo,cName,tNo) values('c007','C語言','t003');
insert into course(cNo,cName,tNo) values('c008','高等數學','t004');

成績表

create table score(
	sNo char(5) not null, -- 教師號
	cNo char(5) not null, -- 課程號
	score double not null, -- 成績
	primary key(sNo,cNo)
);
-- 添加成績數據
insert into score(sNo,cNo,score) values('001','c001',56);
insert into score(sNo,cNo,score) values('001','c002',87);
insert into score(sNo,cNo,score) values('001','c003',69);
insert into score(sNo,cNo,score) values('001','c004',92);
insert into score(sNo,cNo,score) values('002','c001',76);
insert into score(sNo,cNo,score) values('002','c003',69);
insert into score(sNo,cNo,score) values('002','c005',90);
insert into score(sNo,cNo,score) values('003','c002',53);
insert into score(sNo,cNo,score) values('003','c003',96);
insert into score(sNo,cNo,score) values('004','c004',67);
insert into score(sNo,cNo,score) values('005','c008',69);
insert into score(sNo,cNo,score) values('005','c007',78);
insert into score(sNo,cNo,score) values('005','c002',70);
insert into score(sNo,cNo,score) values('005','c003',81);
insert into score(sNo,cNo,score) values('006','c004',93);
insert into score(sNo,cNo,score) values('006','c008',62);
insert into score(sNo,cNo,score) values('007','c001',58);
insert into score(sNo,cNo,score) values('007','c002',76);
insert into score(sNo,cNo,score) values('008','c003',65);
insert into score(sNo,cNo,score) values('008','c004',89);
insert into score(sNo,cNo,score) values('009','c005',92);
insert into score(sNo,cNo,score) values('009','c006',90);
insert into score(sNo,cNo,score) values('009','c007',42);
insert into score(sNo,cNo,score) values('009','c008',80);
insert into score(sNo,cNo,score) values('010','c002',75);
insert into score(sNo,cNo,score) values('010','c004',69);
insert into score(sNo,cNo,score) values('011','c004',92);
insert into score(sNo,cNo,score) values('011','c005',99);
insert into score(sNo,cNo,score) values('011','c002',100);
insert into score(sNo,cNo,score) values('011','c006',76);
insert into score(sNo,cNo,score) values('012','c003',71);
insert into score(sNo,cNo,score) values('012','c002',83);
insert into score(sNo,cNo,score) values('013','c004',80);
insert into score(sNo,cNo,score) values('013','c007',96);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章