【数据库】MySQL习题及答案(教务管理系统_MySQL_5.7)
✨声明
- 不保证习题答案完全正确,仅供参考
- MySQL:5.7
- 推荐软件:Navicat Premium
学习SQL语句需要勤于练习!
✨各表字段说明
course
CId 课程序号,主键
PCId
先修课
DId
开课系编号,外键
CName
课程名称
CCredIT
学分
CHour
学时
CATTr
课程类型
CNum
选课人数
dept
DId 部门编号,主键
DName
部门名称
DAddr
地址
DTele
电话
DEmaI
邮箱
grade
GId 班级编号,主键
DId
系编号,外键
TId
教师工号,外键
GName
班级名称
GYear
入学年份
information
IId 序号,主键
CId
课程序号,外键
TId
教师编号,外键
GId
班级编号,外键
IRoom
上课教室
IWeek
周几上课
ITImeSeg
第几节上课
ITerm
开课学年/学期
sc
SCId 选课序号,主键
CId
课程编号,外键
SId
学号,外键
SCTerm
开课学年/学期
SCScore1
平时成绩
SCScore2
期中成绩
SCScore3
期末成绩
SCScore
总评成绩
student
SId 学号,主键
GId
班级ID,外键
SName
姓名
SSexy
性别
SBdaTedaTe
出生日期
STele
联系电话
teacher
TId 教师工号,主键
DId
系编号,外键
TName
姓名
TSexy
性别
TBdate
出生日期
TField
研究领域
TProf
职称
TTele
联系电话
TQq
QQ号码
TEmail
邮箱
TMsn
MSN
✨经验分享
多表查询注意
首先观察题目涉及哪几张表,需要查询那些数据项
(假设涉及到三张表,需要把三张表中所有有相同字段的全部自然连接起来,然后再进行查询)
注意GROUP BY后面的字段不要填写错误
HAVING需要写在GROUP BY后面
一张表涉及两个及以上操作需要建立临时表
✨习题
1显示院系信息表中的所有信息1
2显示院系信息表中的部门编码、部门名称信息1
3显示所有女教师的工号、姓名、性别信息1
4显示CS系的老师所有个人信息1
5显示CS系与IT系所有老师的全部个人信息1
6显示女教授的姓名、性别、职称与部门编号信息1
7显示研究领域为数据库的老师的姓名、研究领域、联系电话、所在部门1
8显示40岁以下老师的姓名、出生日期1
9显示5月份出生的姓名、性别、出生日期、联系电话1
10显示姓李的老师的所有信息1
11显示选修了1号课程的同学的学号1
12显示同时选修了1号与2号课程的同学的学号2
13显示012005002号同学选修的课程号1
14显示012005002号同学的全部选修信息1
15显示期末成绩不及格的同学的学号、课程号与期末成绩1
16显示选修了1号课程的人数1
17显示1号课程期末考试成绩的平均分1
18显示012005002同学的期末成绩的平均分1
19显示2008年每门课程期末成绩的平均分,显示课程号与平均分,并按降序排列2
20显示周4有课的教室1
21显示周4有课的老师的工号1
22显示NB222教室排课的情况1
23显示1号课程上课的教室、老师工号、上课时间1
24显示02004号老师上课的教室与时间1
25显示第4节有课的教室、课程号、教师工号1
26统计每个教师每周上课的次数及总时长(每节课45分钟)2
27统计每个班每周上课的课时数,显示班级编号和课时数,并按降序排列2
28显示无前导课的课程的全部信息1
29显示CS系所开课程的课程号与课程名1
30显示学分大于3的所有课程的课程名与课时1
31按开课院系统计每个院系开课的学分数,显示院系编号和总学分,并按降序排列2
32显示学生中所有男生的全部信息1
33显示01班所有学生的信息1
34显示03班所有女生的信息1
35显示刘山同学的电话号码1
36显示所有女生的学号、姓名与班级编号1
37统计每个班级的人数,显示班级编号,人数,并按降序排列1
38显示人数5人以上班级的班级编号和人数,并按升序排列2
39显示年龄在18岁以下的学生的全部信息1
40统计18岁以下学生的总人数1
41统计每个班20岁以下的人数,显示班级编号、人数2
42统计每个年龄段的人数,按照年龄升序排列2
43显示姓名中有"白云"的同学的所有信息1
44显示白姓同学的姓名、性别、班级名称、联系电话2
45显示CS系的班级名称及入学年份1
46显示没有班导的班级的所有信息1
47显示2008年入学班级的所有信息1
48显示所有学生的详细信息,包括学号、姓名、性别、年龄、班级名称,入学年份2
49显示信息科学与技术系同学的名单,包括学号、姓名、性别、年龄、班级名称、入学年份2
50显示选修了"数据库"课程的所有同学的学号、姓名2
51显示白云同学的班主任老师的姓名、联系电话2
52显示白云同学所在院系的名称、办公地点与联系电话2
53统计计算机科学与技术系每个同学已经修完的学分,显示学号、姓名、学分总数2
54显示张飞同学已修课程的课程号,课程名及期末成绩2
55显示计算机科学与技术系、信息科学与技术系的班级名称、入学年份、班导名称与联系电话2
56显示2008年入学的同学的学号、姓名、班级名称2
57显示已修数据库的同学的学号、姓名及期末成绩2
58显示期末平均成绩75分以上的课程名称与期末平均成绩2
59显示期末平均成绩80分以上同学的学号、姓名与期末平均成绩2
60显示一周课时数为5节及以上的教师的姓名与研究领域2
61按照班级统计期末平均成绩,显示班级名称与平均成绩2
62按照学期统计计算机科学与技术系学生的期末平均成绩,显示学期名称与平均成绩2
63统计每个院系一周的课时数,显示院系名称与课时数2
64显示没有选修任何课程的学生学号、姓名、班级名称2
65显示上过李飞老师的课的学生的学号、姓名与联系电话2
66显示一周6节课及以上的课程名称、学分2
67显示一周6节课及以上班级名称2
68查询周四上午第3节有课的同学的学号、姓名与班级名称3
69显示期末成绩没有不及格课程的班级的名称3
70显示已修数据库的同学信息,包括学号、姓名、班级名称3
71显示期中成绩不及格1门以上的同学学号、姓名、门数3
72统计每个班级期末成绩的最高分,显示班级名称、期末最高成绩2
73显示一周8节课及以上的学生的名单,显示学号、姓名、班级名称3
74显示计算机科学与技术1班一周上课的时间、地点,课程名称(周几,哪几节课,哪个教室)3
75统计教授每周上课的课时数,显示姓名、课时数3
76显示没有班导师的班级名称、院系名称2
77显示指导过两个班级以上的班导的姓名、所指导的班级名称2
78为洪玉飞老师(教师编号:03012)安排软件工程1班(班级编号:04)的数据库课程(课程编号:1),上课教师为NB2011
79计算机科学与技术3班所有学生都选修了2009-2010-1的操作系统(课程编号为4),请记录相关信息1
80理学院新开一门课程“数学建模”,课程编号20, 学分4,学时72,选修课程,最多选课人数为501
81将李飞同学的联系方式改为6601011
82计算所有学生的总评成绩,公式为:总评=平时*20%+实验*20%+期末*60%1
83将电子信息1班(班级编号:08)的班主任改为洪玉飞老师(无重名)1
84将课程"数据库"的上课教室改为NB111,授课教师改为李飞(教师编号:02001)1
85将学号为012005001的学生班级改为计算机科学与技术3班1
86删除所有期末成绩小于60分的选课记录1
87删除学号为012005001的所有选课记录1
88删除所有选修了"数据库"课程的选课记录1
89删除李飞老师(教师编号:02001)2008学年的排课记录1
90删除所有在NB1楼上课的排课记录1
91删除NB111教室在周四的排课记录1
92删除选修人数小于5的选课记录1
93删除未担任班导师并且未安排课程的教师记录2
94创建一个新的用户,用户名为[alogin],允许该用户在本机访问教务数据库0
95授予新建数据库用户[alogin]对表student和sc的查询权限0
96授予新建数据库用户[alogin]对表student表sname列的更新权限0
97创建一个角色,授予对表course的查询和更新权限,并将该角色授权给新建数据库用户[alogin]0
98为student表增加约束条件,性别字段可以的取值为‘男’,‘女’0
99为student表增加约束条件:性别默认为‘男’0
100为student表增加约束条件:联系方式至少长度为60
101为student表增加约束条件:出生日期小于当前时间0
102为dept表增加约束条件:院系名称必须唯一0
103为grade表增加约束条件:入学年份不能大于当前年份0
104为dept表增加约束条件:联系电话必须为8位数字0
105为information表增加约束条件:学期格式为“xxxx-xxxx-x”,其中xxxx为4位数字表示学年,x为1或者2,表示上下学期。0
106为sc表增加约束条件:各项成绩都在0-100之间0
107删除一个已经存在的约束条件,如果没有先建立约束0
108写一个触发器,使得course中的记录更新时,课程性质只能为“选修”或者“必修”。否则提醒更新失败2
109写一个触发器,使得sc表的新增记录满足下述条件: 公式为:总评=平时*20%+实验*20%+期末*60%2
✨习题及答案
显示院系信息表中的所有信息
SELECT *FROM dept
显示院系信息表中的部门编码、部门名称信息
SELECT DId, DNameFROM dept
显示所有女教师的工号、姓名、性别信息
SELECT TId, TName, TSexyFROM teacher
WHERE TSexy = "女"
显示CS系的老师所有个人信息
SELECT *FROM teacher
WHERE DId = "CS"
显示CS系与IT系所有老师的全部个人信息
SELECT *FROM teacher
WHERE DId = "CS"
OR DId = "IT"
显示女教授的姓名、性别、职称与部门编号信息
SELECT TName, TSexy, TProf, DIdFROM teacher
WHERE TSexy = "女"
AND TProf = "教授"
显示研究领域为数据库的老师的姓名、研究领域、联系电话、所在部门
SELECT TName, TField, TTele, DNameFROM dept,
teacher
WHERE TField = "数据库"
显示40岁以下老师的姓名、出生日期
SELECT TName, YEAR (TBdate) TBdateFROM teacher
WHERE YEAR (NOW())- YEAR (TBdate) < 40
显示5月份出生的姓名、性别、出生日期、联系电话
SELECT TName, TSexy, TBdate, TTeleFROM teacher
WHERE MONTH (TBdate)=5
显示姓李的老师的所有信息
SELECT *FROM teacher
WHERE LEFT (TName, 1)="李"
显示选修了1号课程的同学的学号
SELECT SIdFROM sc
WHERE CId = 1
显示同时选修了1号与2号课程的同学的学号
SELECT SIdFROM sc
WHERE CId = 1
AND SId IN (SELECT SId FROM sc WHERE CId = 2)
显示012005002号同学选修的课程号
SELECT CIdFROM sc
WHERE SId = 012005002
显示012005002号同学的全部选修信息
SELECT *FROM sc
WHERE SId = 012005002
显示期末成绩不及格的同学的学号、课程号与期末成绩
SELECT SId, CId, SCScore3FROM sc
WHERE SCScore3 < 60
显示选修了1号课程的人数
SELECT COUNT(SId)FROM sc
GROUP BY CId
HAVING CID = 1
显示1号课程期末考试成绩的平均分
SELECT CId, AVG(SCScore3)FROM sc
GROUP BY CId
HAVING CId = 1
显示012005002同学的期末成绩的平均分
SELECT DISTINCT SId, AVG(SCScore3)FROM sc
GROUP BY SId
HAVING SId = 012005002
显示2008年每门课程期末成绩的平均分,显示课程号与平均分,并按降序排列
SELECT SId, SCScore3, SCTermFROM sc
WHERE SCTerm in ("2007-2008-2", "2008-2009-1")
ORDER BY SCScore3 DESC
显示周4有课的教室
SELECT IRoomFROM information
WHERE IWeek = 4
显示周4有课的老师的工号
SELECT TIdFROM information
WHERE IWeek = 4
显示NB222教室排课的情况
SELECT DISTINCT IWeek, ITimesegFROM information
WHERE IRoom = "NB222"
显示1号课程上课的教室、老师工号、上课时间
SELECT IRoom, TId, IWeek, ITimesegFROM information
WHERE CId = 1
显示02004号老师上课的教室与时间
SELECT IRoom, IWeek, ITimesegFROM information
WHERE TId = "02004"
显示第4节有课的教室、课程号、教师工号
SELECT IRoom, CId, TIdFROM information
WHERE ITimeseg = 34
OR ITimeseg = 345
统计每个教师每周上课的次数及总时长(每节课45分钟)
SELECT TId, COUNT(*) as Cnt,
SUM(LENGTH(ITimeseg) * 45) as ITime
FROM information
GROUP BY TId
统计每个班每周上课的课时数,显示班级编号和课时数,并按降序排列
SELECT GId, LENGTH(ITimeseg) AS cntFROM information
GROUP BY GId
ORDER BY cnt DESC
显示无前导课的课程的全部信息
SELECT *FROM course
WHERE PCId IS NULL
显示CS系所开课程的课程号与课程名
SELECT CId, CNameFROM course
WHERE DId = "CS"
显示学分大于3的所有课程的课程名与课时
SELECT CName, CNumFROM course
WHERE CCredit > 3
按开课院系统计每个院系开课的学分数,显示院系编号和总学分,并按降序排列
SELECT CId, SUM(CCredit)FROM course
GROUP BY DId
ORDER BY CCredit DESC
显示学生中所有男生的全部信息
SELECT *FROM student
WHERE SSexy = "男"
显示01班所有学生的信息
SELECT *FROM student
WHERE GId = "01"
显示03班所有女生的信息
SELECT *FROM student
WHERE GId = "03"
AND SSexy = "女"
显示刘山同学的电话号码
SELECT STeleFROM student
WHERE SName = "刘山"
显示所有女生的学号、姓名与班级编号
SELECT SId, SName, GIdFROM student
WHERE SSexy = "女"
统计每个班级的人数,显示班级编号,人数,并按降序排列
SELECT GId, COUNT(SName) AS cntFROM student
GROUP BY GId
ORDER BY cnt DESC
显示人数5人以上班级的班级编号和人数,并按升序排列
SELECT GId, COUNT(*) AS cntFROM student
GROUP BY GId
HAVING cnt > 5
ORDER BY cnt
显示年龄在18岁以下的学生的全部信息
SELECT *FROM studentWHERE YEAR (NOW())- YEAR (SBdate)<=18
统计18岁以下学生的总人数
SELECT COUNT(*)FROM studentWHERE YEAR (NOW())- YEAR (SBdate)<=18
统计每个班20岁以下的人数,显示班级编号、人数
SELECT GId, COUNT(GId)FROM student
WHERE TIMESTAMPDIFF(YEAR,SBdate, NOW()) < 20
GROUP BY GId
统计每个年龄段的人数,按照年龄升序排列
SELECT TIMESTAMPDIFF(YEAR,SBdate, NOW()) as age, COUNT(*)FROM student
GROUP BY age
ORDER BY age
-- SELECT YEAR(NOW())-YEAR(SBdate) AS age,COUNT(*) FROM student GROUP BY age ORDER BY age
显示姓名中有白云的同学的所有信息
SELECT *FROM student
WHERE SName LIKE "%白云%"
显示白姓同学的姓名、性别、班级名称、联系电话
SELECT student.SName, student.SSexy, grade.GName, student.STeleFROM student,
grade
WHERE SName LIKE "白%"
AND student.GId = grade.GId
显示CS系的班级名称及入学年份
SELECT DId, GName, GYearFROM grade
WHERE DId = "CS"
显示没有班导的班级的所有信息
SELECT *FROM grade
WHERE TId IS NULL
显示2008年入学班级的所有信息
SELECT *FROM grade
WHERE GYear = 2008
显示所有学生的详细信息,包括学号、姓名、性别、年龄、班级名称,入学年份
SELECT student.SId, student.SName, student.SSexy, TIMESTAMPDIFF(YEAR,SBdate, NOW()) AS age, grade.GName, GYearFROM student, gradeWHERE student.GId = grade.GId
显示信息科学与技术系同学的名单,包括学号、姓名、性别、年龄、班级名称、入学年份
SELECT student.SId, student.SName, student.SSexy, TIMESTAMPDIFF(YEAR,SBdate, NOW()) AS age, grade.GName, GYearFROM student, gradeWHERE student.GId = grade.GId AND grade.DId = "IT"
显示选修了数据库课程的所有同学的学号、姓名
SELECT student.SId, student.SNameFROM student, scWHERE student.SId = sc.SId AND CId = 1
显示白云同学的班主任老师的姓名、联系电话
SELECT teacher.TName, TTeleFROM student,
grade,
teacher
WHERE student.SName = "白云"
AND student.GId = grade.GId
AND grade.TId = teacher.TId
显示白云同学所在院系的名称、办公地点与联系电话
SELECT dept.DName, dept.DAddr, dept.DTeleFROM student,
grade,
dept
WHERE student.SName = "白云"
AND student.GId = grade.GId
AND grade.DId = dept.DId
统计计算机科学与技术系每个同学已经修完的学分,显示学号、姓名、学分总数
SELECT student.SId, SName, SUM(CCredit)FROM student,
grade,
dept,
course,
sc
WHERE student.GId = grade.GId
AND grade.DId = dept.DId
AND dept.DName = "计算机科学与技术系"
AND sc.SId = student.SId
AND SCScore >= 60
AND sc.CId = course.CId
GROUP BY SId
显示张飞同学已修课程的课程号,课程名及期末成绩
SELECT course.CId, course.CName, sc.SCScoreFROM student, sc, courseWHERE student.SName = "张飞" AND student.SId = sc.SId AND sc.CId = course.CId
显示计算机科学与技术系、信息科学与技术系的班级名称、入学年份、班导名称与联系电话
SELECT GName, GYear, TName, TTeleFROM grade,
dept,
teacher
WHERE (dept.DName = "计算机科学与技术系" OR dept.DName = "信息科学与技术系")
AND dept.DId = grade.DId
AND grade.TId = teacher.TId
显示2008年入学的同学的学号、姓名、班级名称
SELECT student.SId, SName, grade.GNameFROM student,
grade
WHERE grade.GYear = 2008
AND student.GId = grade.GId
显示已修数据库的同学的学号、姓名及期末成绩
SELECT DISTINCT student.SId, SName, SCScoreFROM student,
sc,
course
WHERE course.CName = "数据库"
显示期末平均成绩75分以上的课程名称与期末平均成绩
SELECT course.CName, AVG(sc.SCScore)FROM course,
sc
WHERE course.CId = sc.CId
GROUP BY sc.CId
HAVING AVG(sc.SCScore) > 75
显示期末平均成绩80分以上同学的学号、姓名与期末平均成绩
SELECT student.SId, student.SName, sc.SCScoreFROM student,
sc
WHERE student.SId = sc.SId
AND sc.SCScore > 80
显示一周课时数为5节及以上的教师的姓名与研究领域
SELECT TName, TFieldFROM information,
teacher
WHERE information.TId = teacher.TId
GROUP BY teacher.TId
HAVING SUM(LENGTH(ITimeseg)) >= 5
按照班级统计期末平均成绩,显示班级名称与平均成绩
SELECT GName, AVG(sc.SCScore)FROM sc,
grade,
student
WHERE student.SId = sc.SId
AND student.GId = grade.GId
GROUP BY grade.GId
按照学期统计计算机科学与技术系学生的期末平均成绩,显示学期名称与平均成绩
SELECT ITerm, AVG(sc.SCScore3)FROM dept,
grade,
information,
sc,
student
WHERE dept.DName = "计算机科学与技术系"
AND dept.DId = grade.DId
AND sc.SId = student.SId
AND student.GId = grade.GId
AND information.GId = grade.GId
GROUP BY ITerm
统计每个院系一周的课时数,显示院系名称与课时数
SELECT dept.DName, SUM(LENGTH(ITimeseg))FROM dept,
information,
grade
WHERE dept.DId = grade.DId
AND information.GId = grade.GId
GROUP BY dept.DId
显示没有选修任何课程的学生学号、姓名、班级名称
SELECT SId, SName, GNameFROM grade,
student
WHERE grade.GId = student.GId
AND SId NOT IN (SELECT DISTINCT SId FROM sc)
显示上过李飞老师的课的学生的学号、姓名与联系电话
SELECT DISTINCT student.SId, student.SName, student.STeleFROM student,
sc,
information,
teacher
WHERE student.SId = sc.SId
AND information.TId = teacher.TId
AND sc.CId = information.CId
AND teacher.TId IN
(SELECT TId
FROM teacher
WHERE TName = "李飞")
SELECT DISTINCT student.SId, student.SName, student.STele
FROM grade,
student,
information,
teacher,
sc
WHERE teacher.TName = "李飞"
AND teacher.TId = information.TId
AND information.CId = sc.CId
AND sc.SId = student.SId
显示一周6节课及以上的课程名称、学分
SELECT course.CName, course.CCreditFROM course,
information
WHERE course.CId = information.CId
GROUP BY information.CId
HAVING SUM(LENGTH(information.ITimeseg)) > 6
显示一周6节课及以上班级名称
SELECT grade.GNameFROM information,
grade
WHERE information.GId = grade.GId
GROUP BY information.GId
HAVING SUM(LENGTH(information.ITimeseg)) > 6
查询周四上午第3节有课的同学的学号、姓名与班级名称
SELECT DISTINCT student.SId, student.SName, grade.GNameFROM student,
grade,
information
WHERE student.GId = grade.GId
AND information.GId = grade.GId
AND information.GId = student.GId
AND information.IWeek = 4
AND information.ITimeseg LIKE "%3%"
-- AND (information.ITimeseg = 123 OR information.ITimeseg = 345 OR information.ITimeseg = 34)
显示期末成绩没有不及格课程的班级的名称
SELECT DISTINCT grade.GNameFROM grade,
sc,
student
WHERE sc.SCScore >= 60
AND sc.SId = student.SId
AND student.GId = grade.GId
显示已修数据库的同学信息,包括学号、姓名、班级名称
SELECT DISTINCT student.SId, student.SName, grade.GNameFROM student,
grade,
sc,
course
WHERE student.GId = grade.GId
AND sc.CId = course.CId
AND student.SId = sc.SId
AND course.CName = "数据库"
显示期中成绩不及格1门以上的同学学号、姓名、门数
SELECT student.SId, student.SName, COUNT(*)FROM student,
sc
WHERE sc.SCScore2 < 60
AND student.SId = sc.SId
GROUP BY student.SId
HAVING COUNT(*) > 1
统计每个班级期末成绩的最高分,显示班级名称、期末最高成绩
SELECT grade.GName, MAX(sc.SCScore)FROM grade,
sc,
student
WHERE student.SId = sc.SId
AND grade.GId = student.GId
GROUP BY grade.GId
显示一周8节课及以上的学生的名单,显示学号、姓名、班级名称
SELECT student.SId, student.SName, grade.GNameFROM student,
grade,
sc,
information
WHERE student.SId = sc.SId
AND student.GId = grade.GId
AND sc.CId = information.CId
GROUP BY student.SId
HAVING SUM(LENGTH(information.ITimeseg)) >= 8
显示计算机科学与技术1班一周上课的时间、地点,课程名称(周几,哪几节课,哪个教室)
SELECT information.IWeek, information.ITimeseg, information.IRoom, course.CNameFROM information,
course,
grade
WHERE grade.GName = "计算机科学与技术1班"
AND course.CId = information.CId
AND grade.GId = information.GId
统计教授每周上课的课时数,显示姓名、课时数
SELECT teacher.TName, SUM(LENGTH(information.ITimeseg)) AS coursecntFROM teacher,
information
WHERE teacher.TProf = "教授"
AND teacher.TId = information.TId
GROUP BY teacher.TId
显示没有班导师的班级名称、院系名称
SELECT grade.GName, dept.DNameFROM grade,
dept
WHERE grade.DId = dept.DId
AND grade.TId IS NULL
显示指导过两个班级以上的班导的姓名、所指导的班级名称
SELECT TName, GNameFROM grade,
teacher
WHERE grade.TId = teacher.TId
AND grade.TId IN (
SELECT grade.TId
FROM grade
WHERE TId IS NOT NULL
GROUP BY grade.TId
HAVING COUNT(GId) > 2)
为洪玉飞老师(教师编号:03012)安排软件工程1班(班级编号:04)的数据库课程(课程编号:1),上课教师为NB201
INSERTINTO information (IId, TId, GId, CId, IRoom)
SELECT MAX(IId) + "1", "03012", "04", "1", "NB201"
FROM information
计算机科学与技术3班所有学生都选修了2009-2010-1的操作系统(课程编号为4),请记录相关信息
INSERT INTO sc (SCId, SId, CId, SCTerm)
SELECT (@row_number:=@row_number+1) as SCId, student.SId, "4" as CId, "2009-2010-1" as SCTerm
FROM student,
grade,
(SELECT @row_number:=MAX(SCId) FROM sc) as a
WHERE student.GId = grade.GId
AND GName = "计算机科学与技术3班"
理学院新开一门课程“数学建模”,课程编号20, 学分4,学时72,选修课程,最多选课人数为50
INSERTINTO course (CId, CName, CCredit, CHour, CAttr, CNum)VALUES ("20", "数学建模", "4", "72", "选修", "50")
将李飞同学的联系方式改为660101
UPDATE studentSET STele = "660101"WHERE SName = "李飞"
计算所有学生的总评成绩,公式为:总评=平时20%+实验20%+期末*60%
UPDATE scSET SCScore = SCScore1 * 0.2 + SCScore2 * 0.2 + SCScore3 * 0.6
将电子信息1班(班级编号:08)的班主任改为洪玉飞老师(无重名)
UPDATE gradeSET TId = (SELECT TId
FROM teacher
WHERE TName = "洪玉飞")
WHERE GId = 08
将课程数据库的上课教室改为NB111,授课教师改为李飞(教师编号:02001)
UPDATE informationSET IRoom = "NB111",
TId = "02001"
WHERE CId IN
(SELECT CId
FROM course
WHERE CName = "数据库")
将学号为012005001的学生班级改为计算机科学与技术3班
UPDATE studentSET GId =
(SELECT GId
FROM grade
WHERE GName = "计算机科学与技术3班")
WHERE SId = "012005001"
删除所有期末成绩小于60分的选课记录
DELETEFROM scWHERE SCScore3 < 60
删除学号为012005001的所有选课记录
DELETEFROM scWHERE SId = "012005001"
删除所有选修了数据库课程的选课记录
DELETEFROM sc
WHERE CId IN
(SELECT CId
FROM course
WHERE CName = "数据库")
删除李飞老师(教师编号:02001)2008学年的排课记录
DELETEFROM information
WHERE TId = "02001"
AND ITerm LIKE "%2008%"
删除所有在NB1楼上课的排课记录
DELETEFROM information
WHERE IRoom LIKE "NB1%"
删除NB111教室在周四的排课记录
DELETEFROM information
WHERE IRoom = "NB111"
AND IWeek = 4
删除选修人数小于5的选课记录
DELETEFROM sc
WHERE CId IN
(SELECT *
FROM ((SELECT CId
FROM sc
GROUP BY CId
HAVING COUNT(*) < 5) AS tmp))
删除未担任班导师并且未安排课程的教师记录
DELETEFROM teacher
WHERE TId NOT IN
(SELECT TId
FROM grade
WHERE TId IS NOT NULL)
AND TId NOT IN
(SELECT TId
FROM information
WHERE TId IS NOT NULL)
创建一个新的用户,用户名为[alogin],允许该用户在本机访问教务数据库
授予新建数据库用户[alogin]对表student和sc的查询权限
授予新建数据库用户[alogin]对表student表sname列的更新权限
创建一个角色,授予对表course的查询和更新权限,并将该角色授权给新建数据库用户[alogin]
为student表增加约束条件,性别字段可以的取值为‘男’,‘女’
为student表增加约束条件:性别默认为‘男’
为student表增加约束条件:联系方式至少长度为6
为student表增加约束条件:出生日期小于当前时间
为dept表增加约束条件:院系名称必须唯一
为grade表增加约束条件:入学年份不能大于当前年份
为dept表增加约束条件:联系电话必须为8位数字
为information表增加约束条件:学期格式为“xxxx-xxxx-x”,其中xxxx为4位数字表示学年,x为1或者2,表示上下学期。
为sc表增加约束条件:各项成绩都在0-100之间
删除一个已经存在的约束条件,如果没有先建立约束
写一个触发器,使得course中的记录更新时,课程性质只能为“选修”或者“必修”。否则提醒更新失败
写一个触发器,使得sc表的新增记录满足下述条件: 公式为:总评=平时20%+实验20%+期末*60%
✨建库SQL
/* Navicat Premium Data Transfer
Source Server : dbms
Source Server Type : MySQL
Source Server Version : 50732
Source Host : localhost:3306
Source Schema : edu_schema
Target Server Type : MySQL
Target Server Version : 50732
File Encoding : 65001
Date: 05/07/2021 14:19:35
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for course
-- ----------------------------
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`CId` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "课程序号,主键",
`PCId` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "先修课",
`DId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "开课系编号,外键",
`CName` char(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "课程名称",
`CCredit` int(11) NOT NULL COMMENT "学分",
`CHour` int(11) NOT NULL COMMENT "学时",
`CAttr` char(6) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "课程类型",
`CNum` int(11) NOT NULL COMMENT "选课人数",
PRIMARY KEY (`CId`) USING BTREE,
INDEX `FK_Course_Course`(`PCId`) USING BTREE,
INDEX `FK_Course_Dept`(`DId`) USING BTREE,
CONSTRAINT `FK_Course_Course` FOREIGN KEY (`PCId`) REFERENCES `course` (`CId`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_Course_Dept` FOREIGN KEY (`DId`) REFERENCES `dept` (`DId`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "课程表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of course
-- ----------------------------
INSERT INTO `course` VALUES ("1", "5", "CS", "数据库", 4, 72, "必修", 50);
INSERT INTO `course` VALUES ("10", "9", "EM", "统计与审计", 5, 90, "必修", 90);
INSERT INTO `course` VALUES ("11", NULL, "EL", "刺绣", 1, 18, "选修", 50);
INSERT INTO `course` VALUES ("12", NULL, "EL", "家庭保健", 1, 18, "选修", 30);
INSERT INTO `course` VALUES ("2", NULL, "SD", "数学", 3, 54, "必修", 90);
INSERT INTO `course` VALUES ("3", "1", "CS", "信息系统与数据库", 3, 54, "必修", 50);
INSERT INTO `course` VALUES ("4", "6", "CS", "操作系统", 4, 72, "必修", 50);
INSERT INTO `course` VALUES ("5", "7", "CS", "数据结构", 5, 90, "必修", 50);
INSERT INTO `course` VALUES ("6", NULL, "CS", "计算机基础", 3, 54, "必修", 70);
INSERT INTO `course` VALUES ("7", "6", "CS", "C语言", 2, 36, "必修", 70);
INSERT INTO `course` VALUES ("8", NULL, "CS", "计算机组成原理", 3, 54, "选修", 120);
INSERT INTO `course` VALUES ("9", "2", "EM", "会计学原理", 5, 90, "必修", 90);
-- ----------------------------
-- Table structure for dept
-- ----------------------------
DROP TABLE IF EXISTS `dept`;
CREATE TABLE `dept` (
`DId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "部门编号,主键",
`DName` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "部门名称",
`DAddr` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "地址",
`DTele` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "电话",
`DEmail` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "邮箱",
PRIMARY KEY (`DId`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "院系表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of dept
-- ----------------------------
INSERT INTO `dept` VALUES ("CS", "计算机科学与技术系", "SL604", "87678976", "cs@163.com");
INSERT INTO `dept` VALUES ("EL", "外校", NULL, "62765678", NULL);
INSERT INTO `dept` VALUES ("EM", "经济管理系", "SC302", "87464789", "em@163.com");
INSERT INTO `dept` VALUES ("FD", "外语分院", "SA401", "65656798", "fd@163.com");
INSERT INTO `dept` VALUES ("IT", "信息科学与技术系", "SL704", "88767864", "it@163.com");
INSERT INTO `dept` VALUES ("SD", "理学院", "NB309", "67536387", "sd@163.com");
-- ----------------------------
-- Table structure for exercise
-- ----------------------------
DROP TABLE IF EXISTS `exercise`;
CREATE TABLE `exercise` (
`EId` int(11) NOT NULL,
`EContext` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`ELevel` int(11) NULL DEFAULT NULL,
`EAnswer` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`EId`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of exercise
-- ----------------------------
INSERT INTO `exercise` VALUES (1, "显示院系信息表中的所有信息", 1, "");
INSERT INTO `exercise` VALUES (2, "显示院系信息表中的部门编码、部门名称信息", 1, "");
INSERT INTO `exercise` VALUES (3, "显示所有女教师的工号、姓名、性别信息", 1, "");
INSERT INTO `exercise` VALUES (4, "显示CS系的老师所有个人信息", 1, "");
INSERT INTO `exercise` VALUES (5, "显示CS系与IT系所有老师的全部个人信息", 1, "");
INSERT INTO `exercise` VALUES (6, "显示女教授的姓名、性别、职称与部门编号信息", 1, "");
INSERT INTO `exercise` VALUES (7, "显示研究领域为数据库的老师的姓名、研究领域、联系电话、所在部门", 1, "");
INSERT INTO `exercise` VALUES (8, "显示40岁以下老师的姓名、出生日期", 1, "");
INSERT INTO `exercise` VALUES (9, "显示5月份出生的姓名、性别、出生日期、联系电话", 1, "");
INSERT INTO `exercise` VALUES (10, "显示姓李的老师的所有信息", 1, "");
INSERT INTO `exercise` VALUES (11, "显示选修了1号课程的同学的学号", 1, "");
INSERT INTO `exercise` VALUES (12, "显示同时选修了1号与2号课程的同学的学号", 2, "");
INSERT INTO `exercise` VALUES (13, "显示012005002号同学选修的课程号", 1, "");
INSERT INTO `exercise` VALUES (14, "显示012005002号同学的全部选修信息", 1, "");
INSERT INTO `exercise` VALUES (15, "显示期末成绩不及格的同学的学号、课程号与期末成绩", 1, "");
INSERT INTO `exercise` VALUES (16, "显示选修了1号课程的人数", 1, "");
INSERT INTO `exercise` VALUES (17, "显示1号课程期末考试成绩的平均分", 1, "");
INSERT INTO `exercise` VALUES (18, "显示012005002同学的期末成绩的平均分", 1, "");
INSERT INTO `exercise` VALUES (19, "显示2008年每门课程期末成绩的平均分,显示课程号与平均分,并按降序排列", 2, "");
INSERT INTO `exercise` VALUES (20, "显示周4有课的教室", 1, "");
INSERT INTO `exercise` VALUES (21, "显示周4有课的老师的工号", 1, "");
INSERT INTO `exercise` VALUES (22, "显示NB222教室排课的情况", 1, "");
INSERT INTO `exercise` VALUES (23, "显示1号课程上课的教室、老师工号、上课时间", 1, "");
INSERT INTO `exercise` VALUES (24, "显示02004号老师上课的教室与时间", 1, "");
INSERT INTO `exercise` VALUES (25, "显示第4节有课的教室、课程号、教师工号", 1, "");
INSERT INTO `exercise` VALUES (26, "统计每个教师每周上课的次数及总时长(每节课45分钟)", 2, "");
INSERT INTO `exercise` VALUES (27, "统计每个班每周上课的课时数,显示班级编号和课时数,并按降序排列", 2, "");
INSERT INTO `exercise` VALUES (28, "显示无前导课的课程的全部信息", 1, "");
INSERT INTO `exercise` VALUES (29, "显示CS系所开课程的课程号与课程名", 1, "");
INSERT INTO `exercise` VALUES (30, "显示学分大于3的所有课程的课程名与课时", 1, "");
INSERT INTO `exercise` VALUES (31, "按开课院系统计每个院系开课的学分数,显示院系编号和总学分,并按降序排列", 2, "");
INSERT INTO `exercise` VALUES (32, "显示学生中所有男生的全部信息", 1, "");
INSERT INTO `exercise` VALUES (33, "显示01班所有学生的信息", 1, "");
INSERT INTO `exercise` VALUES (34, "显示03班所有女生的信息", 1, "");
INSERT INTO `exercise` VALUES (35, "显示刘山同学的电话号码", 1, "");
INSERT INTO `exercise` VALUES (36, "显示所有女生的学号、姓名与班级编号", 1, "");
INSERT INTO `exercise` VALUES (37, "统计每个班级的人数,显示班级编号,人数,并按降序排列", 1, "");
INSERT INTO `exercise` VALUES (38, "显示人数5人以上班级的班级编号和人数,并按升序排列", 2, "");
INSERT INTO `exercise` VALUES (39, "显示年龄在18岁以下的学生的全部信息", 1, "");
INSERT INTO `exercise` VALUES (40, "统计18岁以下学生的总人数", 1, "");
INSERT INTO `exercise` VALUES (41, "统计每个班20岁以下的人数,显示班级编号、人数", 2, "");
INSERT INTO `exercise` VALUES (42, "统计每个年龄段的人数,按照年龄升序排列", 2, "");
INSERT INTO `exercise` VALUES (43, "显示姓名中有"白云"的同学的所有信息", 1, "");
INSERT INTO `exercise` VALUES (44, "显示白姓同学的姓名、性别、班级名称、联系电话", 2, "");
INSERT INTO `exercise` VALUES (45, "显示CS系的班级名称及入学年份", 1, "");
INSERT INTO `exercise` VALUES (46, "显示没有班导的班级的所有信息", 1, "");
INSERT INTO `exercise` VALUES (47, "显示2008年入学班级的所有信息", 1, "");
INSERT INTO `exercise` VALUES (48, "显示所有学生的详细信息,包括学号、姓名、性别、年龄、班级名称,入学年份", 2, "");
INSERT INTO `exercise` VALUES (49, "显示信息科学与技术系同学的名单,包括学号、姓名、性别、年龄、班级名称、入学年份", 2, "");
INSERT INTO `exercise` VALUES (50, "显示选修了"数据库"课程的所有同学的学号、姓名", 2, "");
INSERT INTO `exercise` VALUES (51, "显示白云同学的班主任老师的姓名、联系电话", 2, "");
INSERT INTO `exercise` VALUES (52, "显示白云同学所在院系的名称、办公地点与联系电话", 2, "");
INSERT INTO `exercise` VALUES (53, "统计计算机科学与技术系每个同学已经修完的学分,显示学号、姓名、学分总数", 2, "");
INSERT INTO `exercise` VALUES (54, "显示张飞同学已修课程的课程号,课程名及期末成绩", 2, "");
INSERT INTO `exercise` VALUES (55, "显示计算机科学与技术系、信息科学与技术系的班级名称、入学年份、班导名称与联系电话", 2, "");
INSERT INTO `exercise` VALUES (56, "显示2008年入学的同学的学号、姓名、班级名称", 2, "");
INSERT INTO `exercise` VALUES (57, "显示已修数据库的同学的学号、姓名及期末成绩", 2, "");
INSERT INTO `exercise` VALUES (58, "显示期末平均成绩75分以上的课程名称与期末平均成绩", 2, "");
INSERT INTO `exercise` VALUES (59, "显示期末平均成绩80分以上同学的学号、姓名与期末平均成绩", 2, "");
INSERT INTO `exercise` VALUES (60, "显示一周课时数为5节及以上的教师的姓名与研究领域", 2, "");
INSERT INTO `exercise` VALUES (61, "按照班级统计期末平均成绩,显示班级名称与平均成绩", 2, "");
INSERT INTO `exercise` VALUES (62, "按照学期统计计算机科学与技术系学生的期末平均成绩,显示学期名称与平均成绩", 2, "");
INSERT INTO `exercise` VALUES (63, "统计每个院系一周的课时数,显示院系名称与课时数", 2, "");
INSERT INTO `exercise` VALUES (64, "显示没有选修任何课程的学生学号、姓名、班级名称", 2, "");
INSERT INTO `exercise` VALUES (65, "显示上过李飞老师的课的学生的学号、姓名与联系电话", 2, "");
INSERT INTO `exercise` VALUES (66, "显示一周6节课及以上的课程名称、学分", 2, "");
INSERT INTO `exercise` VALUES (67, "显示一周6节课及以上班级名称", 2, "");
INSERT INTO `exercise` VALUES (68, "查询周四上午第3节有课的同学的学号、姓名与班级名称", 3, "");
INSERT INTO `exercise` VALUES (69, "显示期末成绩没有不及格课程的班级的名称", 3, "");
INSERT INTO `exercise` VALUES (70, "显示已修数据库的同学信息,包括学号、姓名、班级名称", 3, "");
INSERT INTO `exercise` VALUES (71, "显示期中成绩不及格1门以上的同学学号、姓名、门数", 3, "");
INSERT INTO `exercise` VALUES (72, "统计每个班级期末成绩的最高分,显示班级名称、期末最高成绩", 2, "");
INSERT INTO `exercise` VALUES (73, "显示一周8节课及以上的学生的名单,显示学号、姓名、班级名称", 3, "");
INSERT INTO `exercise` VALUES (74, "显示计算机科学与技术1班一周上课的时间、地点,课程名称(周几,哪几节课,哪个教室)", 3, "");
INSERT INTO `exercise` VALUES (75, "统计教授每周上课的课时数,显示姓名、课时数", 3, "");
INSERT INTO `exercise` VALUES (76, "显示没有班导师的班级名称、院系名称", 2, "");
INSERT INTO `exercise` VALUES (77, "显示指导过两个班级以上的班导的姓名、所指导的班级名称", 2, "");
INSERT INTO `exercise` VALUES (78, "为洪玉飞老师(教师编号:03012)安排软件工程1班(班级编号:04)的数据库课程(课程编号:1),上课教师为NB201", 1, "");
INSERT INTO `exercise` VALUES (79, "计算机科学与技术3班所有学生都选修了2009-2010-1的操作系统(课程编号为4),请记录相关信息", 1, "");
INSERT INTO `exercise` VALUES (80, "理学院新开一门课程“数学建模”,课程编号20, 学分4,学时72,选修课程,最多选课人数为50", 1, "");
INSERT INTO `exercise` VALUES (81, "将李飞同学的联系方式改为660101", 1, "");
INSERT INTO `exercise` VALUES (82, "计算所有学生的总评成绩,公式为:总评=平时*20%+实验*20%+期末*60%", 1, "");
INSERT INTO `exercise` VALUES (83, "将电子信息1班(班级编号:08)的班主任改为洪玉飞老师(无重名)", 1, "");
INSERT INTO `exercise` VALUES (84, "将课程"数据库"的上课教室改为NB111,授课教师改为李飞(教师编号:02001)", 1, "");
INSERT INTO `exercise` VALUES (85, "将学号为012005001的学生班级改为计算机科学与技术3班", 1, "");
INSERT INTO `exercise` VALUES (86, "删除所有期末成绩小于60分的选课记录", 1, "");
INSERT INTO `exercise` VALUES (87, "删除学号为012005001的所有选课记录", 1, "");
INSERT INTO `exercise` VALUES (88, "删除所有选修了"数据库"课程的选课记录", 1, "");
INSERT INTO `exercise` VALUES (89, "删除李飞老师(教师编号:02001)2008学年的排课记录", 1, "");
INSERT INTO `exercise` VALUES (90, "删除所有在NB1楼上课的排课记录", 1, "");
INSERT INTO `exercise` VALUES (91, "删除NB111教室在周四的排课记录", 1, "");
INSERT INTO `exercise` VALUES (92, "删除选修人数小于5的选课记录", 1, "");
INSERT INTO `exercise` VALUES (93, "删除未担任班导师并且未安排课程的教师记录", 2, "");
INSERT INTO `exercise` VALUES (94, "创建一个新的用户,用户名为[alogin],允许该用户在本机访问教务数据库", 0, "");
INSERT INTO `exercise` VALUES (95, "授予新建数据库用户[alogin]对表student和sc的查询权限", 0, "");
INSERT INTO `exercise` VALUES (96, "授予新建数据库用户[alogin]对表student表sname列的更新权限", 0, "");
INSERT INTO `exercise` VALUES (97, "创建一个角色,授予对表course的查询和更新权限,并将该角色授权给新建数据库用户[alogin]", 0, "");
INSERT INTO `exercise` VALUES (98, "为student表增加约束条件,性别字段可以的取值为‘男’,‘女’", 0, "");
INSERT INTO `exercise` VALUES (99, "为student表增加约束条件:性别默认为‘男’", 0, "");
INSERT INTO `exercise` VALUES (100, "为student表增加约束条件:联系方式至少长度为6", 0, "");
INSERT INTO `exercise` VALUES (101, "为student表增加约束条件:出生日期小于当前时间", 0, "");
INSERT INTO `exercise` VALUES (102, "为dept表增加约束条件:院系名称必须唯一", 0, "");
INSERT INTO `exercise` VALUES (103, "为grade表增加约束条件:入学年份不能大于当前年份", 0, "");
INSERT INTO `exercise` VALUES (104, "为dept表增加约束条件:联系电话必须为8位数字", 0, "");
INSERT INTO `exercise` VALUES (105, "为information表增加约束条件:学期格式为“xxxx-xxxx-x”,其中xxxx为4位数字表示学年,x为1或者2,表示上下学期。", 0, "");
INSERT INTO `exercise` VALUES (106, "为sc表增加约束条件:各项成绩都在0-100之间", 0, "");
INSERT INTO `exercise` VALUES (107, "删除一个已经存在的约束条件,如果没有先建立约束", 0, "");
INSERT INTO `exercise` VALUES (108, "写一个触发器,使得course中的记录更新时,课程性质只能为“选修”或者“必修”。否则提醒更新失败", 2, "");
INSERT INTO `exercise` VALUES (109, "写一个触发器,使得sc表的新增记录满足下述条件: 公式为:总评=平时*20%+实验*20%+期末*60%", 2, "");
-- ----------------------------
-- Table structure for grade
-- ----------------------------
DROP TABLE IF EXISTS `grade`;
CREATE TABLE `grade` (
`GId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "班级编号,主键",
`DId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "系编号,外键",
`TId` char(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "教师工号,外键",
`GName` char(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "班级名称",
`GYear` int(11) NULL DEFAULT NULL COMMENT "入学年份",
PRIMARY KEY (`GId`) USING BTREE,
INDEX `FK_Grade_Teacher`(`TId`) USING BTREE,
INDEX `FK_Gradet_Dep`(`DId`) USING BTREE,
CONSTRAINT `FK_FK_Grade_Teacher` FOREIGN KEY (`TId`) REFERENCES `teacher` (`TId`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_FK_Gradet_Dep` FOREIGN KEY (`DId`) REFERENCES `dept` (`DId`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "班级表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of grade
-- ----------------------------
INSERT INTO `grade` VALUES ("01", "CS", "02008", "计算机科学与技术1班", 2006);
INSERT INTO `grade` VALUES ("02", "CS", "02008", "计算机科学与技术2班", 2006);
INSERT INTO `grade` VALUES ("03", "CS", "02008", "计算机科学与技术3班", 2006);
INSERT INTO `grade` VALUES ("04", "CS", "02009", "软件工程1班", 2007);
INSERT INTO `grade` VALUES ("05", "CS", NULL, "软件工程2班", 2007);
INSERT INTO `grade` VALUES ("06", "IT", "03014", "自动化1班", 2008);
INSERT INTO `grade` VALUES ("07", "IT", "03014", "自动化2班", 2008);
INSERT INTO `grade` VALUES ("08", "IT", "03012", "电子信息1班", 2008);
INSERT INTO `grade` VALUES ("09", "IT", NULL, "电子信息2班", 2008);
INSERT INTO `grade` VALUES ("10", "IT", NULL, "电子信息3班", 2008);
INSERT INTO `grade` VALUES ("11", "EM", "03010", "财务管理", 2006);
INSERT INTO `grade` VALUES ("12", "EM", "03011", "旅游管理", 2006);
INSERT INTO `grade` VALUES ("13", "EM", NULL, "营销管理", 2006);
INSERT INTO `grade` VALUES ("14", "EM", NULL, "信息管理", 2006);
INSERT INTO `grade` VALUES ("15", "FD", "03012", "日语", 2005);
INSERT INTO `grade` VALUES ("16", "FD", "03013", "德语1班", 2005);
INSERT INTO `grade` VALUES ("17", "FD", "03013", "德语2班", 2005);
INSERT INTO `grade` VALUES ("18", "SD", NULL, "应用数学1班", 2008);
INSERT INTO `grade` VALUES ("20", "SD", NULL, "选修混合", NULL);
-- ----------------------------
-- Table structure for information
-- ----------------------------
DROP TABLE IF EXISTS `information`;
CREATE TABLE `information` (
`IId` int(11) NOT NULL COMMENT "序号,主键",
`CId` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "课程序号,外键",
`TId` char(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "教师编号,外键",
`GId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "班级编号,外键",
`IRoom` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "上课教室",
`IWeek` int(11) NULL DEFAULT NULL COMMENT "周几上课",
`ITimeseg` char(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "第几节上课",
`ITerm` char(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "开课学年/学期",
PRIMARY KEY (`IId`) USING BTREE,
INDEX `FK_Information_Course`(`CId`) USING BTREE,
INDEX `FK_Information_Grade`(`GId`) USING BTREE,
INDEX `FK_Information_Teacher`(`TId`) USING BTREE,
CONSTRAINT `FK_Information_Course` FOREIGN KEY (`CId`) REFERENCES `course` (`CId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FK_Information_Grade` FOREIGN KEY (`GId`) REFERENCES `grade` (`GId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FK_Information_Teacher` FOREIGN KEY (`TId`) REFERENCES `teacher` (`TId`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "课程信息表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of information
-- ----------------------------
INSERT INTO `information` VALUES (1, "1", "02001", "01", "NB111", 4, "123", "2008-2009-1");
INSERT INTO `information` VALUES (2, "1", "02001", "01", "NB111", 2, "345", "2008-2009-1");
INSERT INTO `information` VALUES (3, "2", "02003", "03", "NB222", 1, "34", "2008-2009-1");
INSERT INTO `information` VALUES (4, "3", "02004", "01", "NB223", 5, "678", "2008-2009-1");
INSERT INTO `information` VALUES (5, "5", "02005", "05", "NB224", 3, "34", "2008-2009-1");
INSERT INTO `information` VALUES (6, "6", "02006", "05", "NB225", 1, "67", "2008-2009-1");
INSERT INTO `information` VALUES (7, "7", "02007", "03", "NB226", 4, "89", "2008-2009-1");
INSERT INTO `information` VALUES (8, "9", "02008", "08", "NB227", 4, "678", "2008-2009-1");
INSERT INTO `information` VALUES (9, "11", "02009", "09", "NB228", 2, "AB", "2008-2009-1");
INSERT INTO `information` VALUES (10, "2", "03010", "02", "NB229", 1, "123", "2008-2009-1");
INSERT INTO `information` VALUES (11, "4", "02001", "02", "NB230", 5, "345", "2008-2009-1");
INSERT INTO `information` VALUES (12, "5", "02002", "03", "NB231", 3, "123", "2008-2009-1");
INSERT INTO `information` VALUES (13, "6", "02003", "09", "NB222", 1, "89", "2008-2009-1");
INSERT INTO `information` VALUES (14, "7", "02004", "13", "NB223", 4, "67", "2008-2009-1");
INSERT INTO `information` VALUES (15, "9", "02005", "15", "NB224", 4, "345", "2008-2009-1");
INSERT INTO `information` VALUES (16, "3", "02006", "13", "NB225", 2, "89", "2008-2009-1");
INSERT INTO `information` VALUES (17, "4", "02007", "15", "NB226", 2, "12", "2008-2009-1");
INSERT INTO `information` VALUES (18, "10", "02008", "03", "NB227", 5, "123", "2008-2009-1");
INSERT INTO `information` VALUES (19, "10", "02009", "20", "NB228", 3, "AB", "2008-2009-1");
INSERT INTO `information` VALUES (20, "12", "03010", "20", "NB229", 1, "AB", "2008-2009-1");
INSERT INTO `information` VALUES (21, "4", "02001", "12", "NB230", 2, "34", "2008-2009-1");
INSERT INTO `information` VALUES (22, "3", "02002", "09", "NB231", 4, "345", "2008-2009-1");
INSERT INTO `information` VALUES (24, "1", "02001", "09", "NB111", 5, "12", "2008-2009-1");
-- ----------------------------
-- Table structure for sc
-- ----------------------------
DROP TABLE IF EXISTS `sc`;
CREATE TABLE `sc` (
`SCId` int(11) NOT NULL COMMENT "选课序号,主键",
`CId` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "课程编号,外键",
`SId` char(9) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "学号,外键",
`SCTerm` char(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "开课学年/学期",
`SCScore1` float NULL DEFAULT NULL COMMENT "平时成绩",
`SCScore2` float NULL DEFAULT NULL COMMENT "期中成绩",
`SCScore3` float NULL DEFAULT NULL COMMENT "期末成绩",
`SCScore` float NULL DEFAULT NULL COMMENT "总评成绩",
PRIMARY KEY (`SCId`) USING BTREE,
INDEX `FK_SC_Course`(`CId`) USING BTREE,
INDEX `FK_SC_Student`(`SId`) USING BTREE,
CONSTRAINT `FK_SC_Course` FOREIGN KEY (`CId`) REFERENCES `course` (`CId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FK_SC_Student` FOREIGN KEY (`SId`) REFERENCES `student` (`SId`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "选课信息表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of sc
-- ----------------------------
INSERT INTO `sc` VALUES (2, "1", "012005002", "2008-2009-1", 99, 60, 70, 76.3333);
INSERT INTO `sc` VALUES (3, "1", "012005003", "2008-2009-1", 99, 44, 88, 77);
INSERT INTO `sc` VALUES (4, "1", "012005004", "2008-2009-1", 99, 78, 67, 81.3333);
INSERT INTO `sc` VALUES (5, "1", "032005005", "2008-2009-1", 99, 65, 87, 83.6667);
INSERT INTO `sc` VALUES (6, "1", "032005006", "2008-2009-1", 99, 76, 98, 91);
INSERT INTO `sc` VALUES (7, "1", "032005007", "2008-2009-1", 99, 56, 78, 77.6667);
INSERT INTO `sc` VALUES (20, "5", "082005009", "2008-2009-2", 99, 78, 83, 86.6667);
INSERT INTO `sc` VALUES (21, "5", "092005010", "2008-2009-2", 99, 77, 63, 79.6667);
INSERT INTO `sc` VALUES (22, "5", "112005011", "2008-2009-2", 99, 90, 74, 87.6667);
INSERT INTO `sc` VALUES (23, "5", "112005012", "2008-2009-2", 99, 45, 83, 75.6667);
INSERT INTO `sc` VALUES (24, "5", "112005013", "2008-2009-2", 99, 89, 73, 87);
INSERT INTO `sc` VALUES (25, "10", "012006001", "2008-2009-2", 99, 67, 73, 79.6667);
INSERT INTO `sc` VALUES (26, "10", "012006002", "2008-2009-2", 99, 36, 82, 72.3333);
INSERT INTO `sc` VALUES (27, "10", "012006003", "2008-2009-2", 99, 87, 83, 89.6667);
INSERT INTO `sc` VALUES (28, "10", "012006004", "2008-2009-2", 99, 54, 73, 75.3333);
INSERT INTO `sc` VALUES (29, "10", "032006005", "2008-2009-2", 99, 45, 73, 72.3333);
INSERT INTO `sc` VALUES (30, "10", "032006006", "2008-2009-2", 99, 78, 83, 86.6667);
INSERT INTO `sc` VALUES (31, "10", "032006007", "2008-2009-2", 99, 72, 84, 85);
INSERT INTO `sc` VALUES (32, "10", "082006008", "2007-2008-2", 99, 60, 78, 79);
INSERT INTO `sc` VALUES (33, "12", "082006009", "2007-2008-2", 99, 60, 73, 77.3333);
INSERT INTO `sc` VALUES (34, "12", "092006010", "2007-2008-2", 99, 90, 83, 90.6667);
INSERT INTO `sc` VALUES (35, "12", "112006011", "2007-2008-2", 99, 89, 62, 83.3333);
INSERT INTO `sc` VALUES (36, "12", "112006012", "2007-2008-2", 99, 89, 65, 84.3333);
INSERT INTO `sc` VALUES (37, "12", "112006013", "2007-2008-2", 99, 78, 65, 80.6667);
INSERT INTO `sc` VALUES (38, "11", "012007001", "2007-2008-2", 99, 65, 67, 77);
INSERT INTO `sc` VALUES (39, "11", "012007002", "2007-2008-2", 99, 76, 78, 84.3333);
INSERT INTO `sc` VALUES (40, "11", "012007003", "2007-2008-2", 99, 56, 79, 78);
INSERT INTO `sc` VALUES (41, "11", "012007004", "2007-2008-2", 99, 50, 76, 75);
INSERT INTO `sc` VALUES (42, "11", "032007005", "2007-2008-2", 99, 78, 71, 82.6667);
INSERT INTO `sc` VALUES (43, "11", "032007006", "2007-2008-2", 99, 98, 81, 92.6667);
INSERT INTO `sc` VALUES (44, "11", "032007007", "2007-2008-2", 99, 79, 82, 86.6667);
INSERT INTO `sc` VALUES (45, "9", "082007008", "2007-2008-2", 99, 93, 62, 84.6667);
INSERT INTO `sc` VALUES (46, "9", "082007009", "2007-2008-2", 99, 72, 63, 78);
INSERT INTO `sc` VALUES (47, "9", "092007010", "2008-2009-1", 99, 89, 69, 85.6667);
INSERT INTO `sc` VALUES (48, "9", "112007011", "2008-2009-1", 99, 86, 68, 84.3333);
INSERT INTO `sc` VALUES (49, "9", "112007012", "2008-2009-1", 99, 80, 76, 85);
INSERT INTO `sc` VALUES (50, "9", "112007013", "2008-2009-1", 99, 88, 83, 90);
INSERT INTO `sc` VALUES (52, "9", "012005002", "2008-2009-1", 99, 54, 76, 76.3333);
INSERT INTO `sc` VALUES (53, "9", "012005003", "2008-2009-1", 99, 78, 76, 84.3333);
INSERT INTO `sc` VALUES (54, "9", "012005004", "2008-2009-1", 99, 77, 56, 77.3333);
INSERT INTO `sc` VALUES (55, "2", "032005005", "2008-2009-1", 99, 90, 65, 84.6667);
INSERT INTO `sc` VALUES (56, "2", "032005006", "2008-2009-1", 99, 45, 65, 69.6667);
INSERT INTO `sc` VALUES (57, "2", "032005007", "2008-2009-1", 99, 89, 76, 88);
INSERT INTO `sc` VALUES (58, "2", "082005008", "2008-2009-1", 99, 67, 45, 70.3333);
INSERT INTO `sc` VALUES (59, "2", "082005009", "2008-2009-1", 99, 36, 84, 73);
INSERT INTO `sc` VALUES (60, "2", "092005010", "2008-2009-1", 99, 87, 90, 92);
INSERT INTO `sc` VALUES (61, "2", "112005011", "2008-2009-1", 99, 54, 93, 82);
INSERT INTO `sc` VALUES (62, "2", "112005012", "2008-2009-1", 99, 45, 67, 70.3333);
INSERT INTO `sc` VALUES (63, "2", "112005013", "2008-2009-1", 99, 78, 64, 80.3333);
INSERT INTO `sc` VALUES (64, "2", "012006001", "2008-2009-1", 99, 72, 63, 78);
INSERT INTO `sc` VALUES (65, "6", "012006002", "2008-2009-1", 99, 60, 48, 69);
INSERT INTO `sc` VALUES (66, "6", "012006003", "2008-2009-1", 99, 60, 76, 78.3333);
INSERT INTO `sc` VALUES (67, "6", "012006004", "2008-2009-1", 99, 90, 65, 84.6667);
INSERT INTO `sc` VALUES (68, "6", "032006005", "2008-2009-1", 99, 89, 76, 88);
INSERT INTO `sc` VALUES (69, "6", "032006006", "2008-2009-1", 99, 89, 46, 78);
INSERT INTO `sc` VALUES (70, "6", "032006007", "2008-2009-1", 99, 78, 85, 87.3333);
INSERT INTO `sc` VALUES (71, "6", "082006008", "2008-2009-1", 99, 65, 65, 76.3333);
INSERT INTO `sc` VALUES (72, "6", "082006009", "2008-2009-1", 99, 76, 54, 76.3333);
INSERT INTO `sc` VALUES (73, "6", "092006010", "2007-2008-1", 99, 56, 65, 73.3333);
INSERT INTO `sc` VALUES (74, "6", "112006011", "2007-2008-1", 99, 50, 65, 71.3333);
INSERT INTO `sc` VALUES (75, "6", "112006012", "2007-2008-1", 99, 78, 74, 83.6667);
INSERT INTO `sc` VALUES (76, "6", "112006013", "2007-2008-1", 99, 98, 74, 90.3333);
INSERT INTO `sc` VALUES (77, "7", "012007001", "2007-2008-1", 99, 79, 83, 87);
INSERT INTO `sc` VALUES (78, "7", "012007002", "2007-2008-1", 99, 93, 94, 95.3333);
INSERT INTO `sc` VALUES (79, "7", "012007003", "2007-2008-1", 99, 72, 73, 81.3333);
INSERT INTO `sc` VALUES (80, "7", "012007004", "2007-2008-1", 99, 89, 83, 90.3333);
INSERT INTO `sc` VALUES (81, "7", "032007005", "2007-2008-1", 99, 86, 63, 82.6667);
INSERT INTO `sc` VALUES (82, "7", "032007006", "2007-2008-1", 99, 80, 67, 82);
INSERT INTO `sc` VALUES (83, "7", "032007007", "2007-2008-1", 99, 88, 84, 90.3333);
INSERT INTO `sc` VALUES (84, "7", "082007008", "2007-2008-1", 99, 67, 96, 87.3333);
INSERT INTO `sc` VALUES (85, "7", "082007009", "2007-2008-1", 99, 65, 90, 84.6667);
INSERT INTO `sc` VALUES (86, "7", "092007010", "2007-2008-1", 99, 78, 92, 89.6667);
INSERT INTO `sc` VALUES (87, "7", "112007011", "2007-2008-1", 99, 77, 86, 87.3333);
INSERT INTO `sc` VALUES (88, "7", "112007012", "2007-2008-1", 99, 90, 80, 89.6667);
INSERT INTO `sc` VALUES (89, "7", "112007013", "2007-2008-1", 99, 45, 80, 74.6667);
-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`SId` char(9) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "学号,主键",
`GId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "班级ID,外键",
`SName` char(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "姓名",
`SSexy` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT "男" COMMENT "性别",
`SBdate` date NOT NULL COMMENT "出生日期",
`STele` char(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "联系电话",
PRIMARY KEY (`SId`) USING BTREE,
INDEX `FK_Student_Grade`(`GId`) USING BTREE,
CONSTRAINT `FK_Student_Grade` FOREIGN KEY (`GId`) REFERENCES `grade` (`GId`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "学生信息表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO `student` VALUES ("012005001", "03", "李山", "男", "1998-10-11", "660780");
INSERT INTO `student` VALUES ("012005002", "01", "张飞", "男", "1997-10-11", "660781");
INSERT INTO `student` VALUES ("012005003", "01", "李玉和", "女", "1999-10-11", "660782");
INSERT INTO `student` VALUES ("012005004", "01", "王一飞", "女", "2000-10-11", "660783");
INSERT INTO `student` VALUES ("012006001", "01", "韦宝", "男", "1998-10-11", "660780");
INSERT INTO `student` VALUES ("012006002", "01", "李飞", "男", "1997-10-11", "660101");
INSERT INTO `student` VALUES ("012006003", "01", "冯玉", "女", "1999-10-11", "660782");
INSERT INTO `student` VALUES ("012006004", "01", "马观", "女", "2000-10-11", "660783");
INSERT INTO `student` VALUES ("012007001", "01", "李知", "男", "1998-10-11", "660780");
INSERT INTO `student` VALUES ("012007002", "01", "吴飞", "男", "1997-10-11", "660781");
INSERT INTO `student` VALUES ("012007003", "01", "李凡", "女", "1999-10-11", "660782");
INSERT INTO `student` VALUES ("012007004", "01", "王二飞", "女", "2000-10-11", "660783");
INSERT INTO `student` VALUES ("032005005", "03", "徐红", "女", "1998-01-11", "660784");
INSERT INTO `student` VALUES ("032005006", "03", "刘和", "男", "1998-12-11", "660785");
INSERT INTO `student` VALUES ("032005007", "03", "刘山", "男", "1999-10-01", "660786");
INSERT INTO `student` VALUES ("032006005", "03", "徐一红", "女", "1998-01-11", "660784");
INSERT INTO `student` VALUES ("032006006", "03", "刘一和", "男", "1998-12-11", "660785");
INSERT INTO `student` VALUES ("032006007", "03", "马西", "男", "1999-10-01", "660786");
INSERT INTO `student` VALUES ("032007005", "03", "王红", "女", "1998-01-11", "660784");
INSERT INTO `student` VALUES ("032007006", "03", "王一红", "男", "1998-12-11", "660785");
INSERT INTO `student` VALUES ("032007007", "03", "丁西", "男", "1999-10-01", "660786");
INSERT INTO `student` VALUES ("082005008", "08", "刘去山", "女", "2000-01-11", "660787");
INSERT INTO `student` VALUES ("082005009", "08", "白云飞", "女", "2002-10-11", "660788");
INSERT INTO `student` VALUES ("082006008", "08", "刘问计", "女", "2000-01-11", "660787");
INSERT INTO `student` VALUES ("082006009", "08", "白问礼", "女", "2002-10-11", "660788");
INSERT INTO `student` VALUES ("082007008", "08", "刘红丽", "女", "2000-01-11", "660787");
INSERT INTO `student` VALUES ("082007009", "08", "沈学云", "女", "2002-10-11", "660788");
INSERT INTO `student` VALUES ("092005010", "08", "白云", "女", "1998-11-11", "660789");
INSERT INTO `student` VALUES ("092006010", "09", "黑土", "女", "1998-12-11", "660788");
INSERT INTO `student` VALUES ("092007010", "09", "李风", "女", "1998-11-11", "660789");
INSERT INTO `student` VALUES ("112005011", "11", "李红", "女", "1997-12-11", "660790");
INSERT INTO `student` VALUES ("112005012", "11", "周磊", "男", "1996-06-11", "660791");
INSERT INTO `student` VALUES ("112005013", "11", "冯圭", "女", "1997-08-11", "660792");
INSERT INTO `student` VALUES ("112006011", "11", "李玉红", "女", "1997-12-11", "660790");
INSERT INTO `student` VALUES ("112006012", "11", "冯磊", "男", "2006-06-11", "660791");
INSERT INTO `student` VALUES ("112006013", "11", "冯由", "女", "2007-08-11", "660792");
INSERT INTO `student` VALUES ("112007011", "11", "刘好", "女", "1997-12-11", "660790");
INSERT INTO `student` VALUES ("112007012", "11", "周成", "男", "1996-06-11", "660791");
INSERT INTO `student` VALUES ("112007013", "11", "文成", "女", "1997-08-11", "660792");
INSERT INTO `student` VALUES ("112007014", "11", "霍去病", "男", "1999-05-09", "660793");
-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher` (
`TId` char(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "教师工号,主键",
`DId` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "系编号,外键",
`TName` char(8) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "姓名",
`TSexy` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "性别",
`TBdate` date NOT NULL COMMENT "出生日期",
`TField` char(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "研究领域",
`TProf` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT "职称",
`TTele` char(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "联系电话",
`TQq` char(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "QQ号码",
`TEmail` char(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "邮箱",
`TMsn` char(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT "MSN",
PRIMARY KEY (`TId`) USING BTREE,
INDEX `FK_Teacher_Dept`(`DId`) USING BTREE,
CONSTRAINT `FK_Teacher_Dept` FOREIGN KEY (`DId`) REFERENCES `dept` (`DId`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = "教师信息表" ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of teacher
-- ----------------------------
INSERT INTO `teacher` VALUES ("02001", "CS", "李飞", "男", "1986-05-05", "数据库", "讲师", "660001", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02002", "CS", "郭山", "男", "1980-06-09", "数据库", "副教授", "660002", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02003", "CS", "马骊", "女", "1983-03-08", "网络技术与数据库", "教授", "660003", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02004", "CS", "徐守", "女", "1980-06-09", "面向对象编程", "助教", "660004", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02005", "CS", "金贵", "女", "1980-06-09", "财务管理", "助教", "660005", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02006", "IT", "成山云", "男", "1984-11-02", "金融学", "教授", "660006", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02007", "IT", "张田下", "男", "1977-01-07", "新能源技术", "研究员", "660007", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02008", "IT", "王一钱", "女", "1965-03-03", "信息管理与数据库", "讲师", "660008", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("02009", "IT", "李远", "女", "1977-01-07", "电工学", "实验师", "660009", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03010", "IT", "吴天贵", "女", "1984-04-26", "中医学", "主治医师", "660010", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03011", "EM", "刘了了", "女", "1972-06-12", "近代史", "研究员", "660220", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03012", "EM", "洪玉飞", "男", "1967-09-29", "哲学", "教授", "660222", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03013", "EM", "划计成", "女", "1962-09-01", "应用数学", "教授", "660223", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03014", "EM", "李丽青", "男", "1968-05-09", "应用物理", "讲师", "660233", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03015", "FD", "李员", "男", "1971-09-15", "统计学", "研究员", "660234", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03016", "FD", "国威", "女", "1965-04-30", "政治学", "研究员", "660123", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("03017", "FD", "国华", "女", "1989-05-29", "证券投资", "研究员", "660987", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("05022", "SD", "后羿", "女", "1983-06-16", "护理与营养", "主任护理师", "660909", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("05023", "SD", "王飞红", "男", "1975-11-20", "多媒体技术", "讲师", "660938", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("05024", "SD", "李丽青", "男", "1969-03-30", "理论力学", "副教授", "660323", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("05025", "SD", "王红", "女", "1970-06-15", "建筑学", "副教授", "660099", NULL, NULL, NULL);
INSERT INTO `teacher` VALUES ("05026", "SD", "李飞", "女", "1963-12-22", "流体力学", "讲师", "660987", NULL, NULL, NULL);
-- ----------------------------
-- View structure for v_sd
-- ----------------------------
DROP VIEW IF EXISTS `v_sd`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_sd` AS (select `student`.`SId` AS `SId`,`student`.`SName` AS `SName`,`course`.`CName` AS `CName`,`sc`.`SCScore1` AS `SCScore1` from ((`student` join `sc`) join `course`) where ((`student`.`SId` = `sc`.`SId`) and (`sc`.`CId` = `course`.`CId`) and (`course`.`CName` = "数据库")));
-- ----------------------------
-- View structure for v_sg
-- ----------------------------
DROP VIEW IF EXISTS `v_sg`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_sg` AS select `student`.`SId` AS `SId`,`student`.`SName` AS `SName`,`grade`.`GName` AS `GName`,`grade`.`GYear` AS `GYear` from (`student` join `grade` on((`student`.`GId` = `grade`.`GId`)));
-- ----------------------------
-- Procedure structure for pro_five_grade
-- ----------------------------
DROP PROCEDURE IF EXISTS `pro_five_grade`;
delimiter ;;
CREATE PROCEDURE `pro_five_grade`()
BEGIN
-- 需要定义接收游标数据的变量
DECLARE A INT DEFAULT 0;
DECLARE B INT DEFAULT 0;
DECLARE C INT DEFAULT 0;
DECLARE D INT DEFAULT 0;
DECLARE E INT DEFAULT 0;
DECLARE score FLOAT;
-- 遍历数据结束标志
DECLARE done INT DEFAULT FALSE;
-- 游标
DECLARE cur CURSOR FOR SELECT SCScore FROM sc;
-- 将结束标志绑定到游标
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 打开游标
OPEN cur;
-- 开始循环
read_loop: LOOP
-- 提取游标里的数据,这里只有一个,多个的话也一样;
FETCH cur INTO score;
-- 声明结束的时候
IF done THEN
LEAVE read_loop;
END IF;
IF score>90 THEN
SET A=A+1 ;
ELSEIF score>80 THEN
SET B=B+1;
ELSEIF score>70 THEN
SET C=C+1;
ELSEIF score>60 THEN
SET D=D+1;
ELSE
SET E=E+1;
END IF;
END LOOP;
-- 关闭游标
CLOSE cur;
-- 输出结果
SELECT A;
SELECT B;
SELECT C;
SELECT D;
SELECT E;
END
;;
delimiter ;
-- ----------------------------
-- Procedure structure for pro_sum
-- ----------------------------
DROP PROCEDURE IF EXISTS `pro_sum`;
delimiter ;;
CREATE PROCEDURE `pro_sum`(m INT, n INT, OUT result INT)
BEGIN
SET result = m + n;
END
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table sc
-- ----------------------------
DROP TRIGGER IF EXISTS `tri_update_sc`;
delimiter ;;
CREATE TRIGGER `tri_update_sc` BEFORE UPDATE ON `sc` FOR EACH ROW BEGIN
set new.SCScore=(new.SCScore1+new.SCScore2+new.SCScore3)/3;
END
;;
delimiter ;
-- ----------------------------
-- Triggers structure for table student
-- ----------------------------
DROP TRIGGER IF EXISTS `tri_ins_num`;
delimiter ;;
CREATE TRIGGER `tri_ins_num` AFTER INSERT ON `student` FOR EACH ROW BEGIN
#select count(*) into @num from student;
insert into tb_count values(new.SId);
END
;;
delimiter ;
SET FOREIGN_KEY_CHECKS = 1;
⭐转载请注明出处
本文作者:双份浓缩馥芮白
原文链接:https://www.cnblogs.com/Flat-White/p/14972243.html
版权所有,如需转载请注明出处。
posted @
2021-07-05 14:31
双份浓缩馥芮白
阅读(5)
评论(0)
编辑
收藏
举报
刷新评论刷新页面返回顶部
Copyright © 2021 双份浓缩馥芮白
Powered by .NET 5.0 on Kubernetes