Mysql 案例-教学管理信息系统 一、数据库设计及创建二、向表中插入数据、修改数据三、完成以下查询设计及SQL代码四、完成如下数据库应用设计 一、数据库设计及创建 对教学管理信息系统,在需求分析阶段,收集到以下信息。 学生的信
对教学管理信息系统,在需求分析阶段,收集到以下信息。
学生的信息:学生的学号、姓名、性别、出生日期、电话(11位)、所在学院、年级、籍贯、民族;学院的信息:学院名称、地址、办公室电话(格式为4位区号-8位电话号码)、联系人、学院简介、所在校区(呈贡/东陆);课程信息:课程号、课程名称、开课学期、周学时、学分、课程性质(选修/必修)、上课教师。此外还有每个学生选修课程的成绩信息。
以下为需求(1)解决方案
数据库:StudentScoreDB
字段名 | 含义 | 数据类型 | 宽度 |
---|---|---|---|
studentNo | 学号 | 字符型 | 10 |
name | 姓名 | 字符型 | 20 |
gender | 性别 | 字符型 | 2 |
birthday | 出生日期 | 日期型 | —— |
telnumber | 电话(11位) | 字符型 | 11 |
college | 所在学院 | 字符型 | 50 |
grade | 年级 | 字符型 | 6 |
place | 籍贯 | 字符型 | 20 |
natiom | 民族 | 字符型 | 30 |
学院信息表:CollegeTb
字段名 | 含义 | 数据类型 | 宽度 |
---|---|---|---|
college | 学院名称 | 字符型 | 40 |
address | 地址 | 字符型 | 50 |
telnumber | 办公室电话(格式为4位区号-8位电话号码) | 字符型 | 13 |
contacts | 联系人 | 字符型 | 20 |
introduction | 学院简介 | 字符型 | 50 |
campus | 所在校区(呈贡/东陆) | 字符型 | 4 |
课程信息表:CourseTb
字段名 | 含义 | 数据类型 | 宽度 |
---|---|---|---|
courseNo | 课程号 | 字符型 | 6 |
courseName | 课程名称 | 字符型 | 40 |
term | 开课学期 | 字符型 | 5 |
weekNumber | 周学时 | 数值型 | —— |
credit | 学分 | 数值型 | —— |
courseType | 课程性质(选修/必修) | 字符型 | 5 |
teacher | 上课教师 | 字符型 | 20 |
选课信息表:ScoreTb
字段名 | 含义 | 数据类型 | 宽度 |
---|---|---|---|
studentNo | 学号 | 字符型 | 10 |
courseNo | 课程号 | 字符型 | 6 |
term | 开课学期 | 字符型 | 5 |
score | 成绩 | 数值型 | —— |
方案:
创建数据库:StudentScoreDB
create database if not exists StudentScoreDB default character set GB2312 default collate GB2312_chinese_ci;show databases;use StudentScoreDB;
方案:
创建学生信息表:StudentTb
create table StudentTb (studentNo char(10) primary key comment '学号', name varchar(20) not null comment '姓名',gender char(2) not null check(gender in ('男','女')) comment '性别', birthday date comment '出生日期',telnumber char(11) comment '电话',college varchar(50) default '工商管理与旅游管理' comment '所在学院',grade char(6) comment '年级',place varchar(20) comment '籍贯',natiom varchar(30) default '汉' comment '民族') ;
创建学院信息表:CollegeTb
create table CollegeTb (college varchar(40) primary key comment '学院名称', address varchar(50) comment '地址',telnumber char(13) comment '办公室电话',contacts varchar(20) comment '联系人', introduction varchar(50) comment '学院简介', campus char(4) check(campus in ('呈贡','东陆')) comment '所在校区') ;
创建课程信息表:CourseTb
create table CourseTb (courseNo char(6) primary key comment '课程号',courseName varchar(40) not null comment '课程名称',term char(5) comment '开课学期',weekNumber tinyint comment '周学时',credit tinyint comment '学分',courseType char(4) check(courseType in ('选修', '必修')) comment '课程性质', teacher varchar(20) comment '上课教师');
创建选课信息表:ScoreTb
create table ScoreTb (studentNo char(10) not null comment '学号',courseNo char(6) not null comment '课程号',term char(5) comment '开课学期',score float check(score>=0 and score<=100) comment '成绩',constraint PK_student foreign key (studentNo) references StudentTb(studentNo),constraint PK_course foreign key (courseNo) references CourseTb(courseNo)) ;show tables;
上面代码最后一行show tables;
为查看该数据库中所有表格。
根据前面设计的数据库和表,向表中插入数据。
方案:
show columns from StudentTb;insert into StudentTb values('2018110101', '张晓勇', '男', '1997-12-11', '15736411111', '信息学院', '2018级','北京','汉'),('2017110102', '赵婷婷', '女', '1996-11-17', '13624722222', '信息学院', '2017级', '上海', '汉'),('2022110103', '王一敏', '女', '2000-01-02', '18875033333', '新闻学院', '2022级','云南','苗'),('2022110104', '李明', '男', '2001-06-21', '19925644444', '建规学院', '2022级','贵州','维吾尔'),('2022040231', '白浩云 ', '男', '2003-08-01', '13848655555', '工商管理与旅游管理 ', '2022级','云南','傈僳' );select * from StudentTb;
方案:
show columns from CourseTb;insert into CourseTb(courseNo, courseName) values('202201' ,'MySQL数据库程序设计'),('202202' ,'python程序设计'),('202203' ,'Java程序设计'),('202204' ,'PHP程序设计'),('202205' ,'html网页设计');select * from CourseTb;
方案:
show columns from CollegeTb;insert into CollegeTb(college,address, telnumber, introduction, campus) values('信息学院', '云大呈贡1号','1111-11111111','信息与技术学院简介:...','呈贡'),('工商管理与旅游管理学院', '云大呈贡2号','2222-22222222','工商管理与旅游管理简介:...','呈贡'),('新闻学院', '云大呈贡3号','3333-33333333','新闻与传播学院简介:...','呈贡'),('文学学院', '云大东陆1号','4444-44444444','文学学院简介:....','东陆'),('建规学院', '云大呈贡1号','5555-55555555','建设与规划学院简介:....','呈贡');select * from CollegeTb;
假定前面设计的数据库各表中已存储了数据。
方案:
update CollegeTb set contacts='白浩云' where college='工商管理与旅游管理学院';select * from CollegeTb;
方案:
insert into ScoreTb values('2018110101','202201', '20222',70),('2017110102','202201', '20222',80),('2022110103','202201', '20222',65),('2022110104','202204', '20222',88),('2021110105','202202', '20222',78);select * from ScoreTb;update ScoreTb set score = score + 5 where courseNo=(select courseNo from CourseTb where courseName='MySQL数据库程序设计');select * from ScoreTb;
假定前面设计的数据库各表中已存储了数据。
答:order by排序列尽可能的选择数值,更具有实际意义。
方案:
select studentNo,name, gender, birthday from StudentTb where grade= '2017级' or natiom='汉' and gender='男' order by studentNo desc limit 10;
答:所设计的查询要求:select、from、where、group by、having、order by、limit 以上语法顺序是不能前后互换的,否则报错。比如我们不能在 group by 之后添加 where 查询语句,否则会出现错误。
方案:
select avg(score), count(score) from ScoreTb group by courseNo;
答:查询期末分数在80分以上的学生姓名以及课程名称和分数;
思路:从选课信息表出发,设置连接条件,学号连接到学生信息表。课程号连接到课程信息表。
方案:
select s.name, c.courseName, e.score from ScoreTb as e, CourseTb as c, StudentTb as swhere e.score>=80 and e.studentNo=s.studentNo and e.courseNo=c.courseNo;
方案:
select * from StudentTb where datediff(CURDATE(),birthday) <= datediff(CURDATE(),(select birthday from StudentTb where studentNo='2021110105' )) and college in (select college from StudentTb where studentNo='2021110105' );
方案:
select * from CollegeTb where campus in (select campus from CollegeTb where college= (select college from StudentTb where studentNo='2021110105'));
假定前面设计的数据库各表中已存储了数据,完成以下要求。
方案:
create index index_college on CollegeTb(college(3) DESC);show index from CollegeTb;
方案:
create or replace view v_College AS select * from CollegeTb where campus='呈贡' with check option;show create view v_College;
方案:
create or replace view v_ScoreTb(studentNo ,name ,courseName, score)AS select s.studentNo, s.name, c.courseName, e.score from StudentTb as s, CourseTb as c, ScoreTb as e where e.studentNo=s.studentNo;show create view v_ScoreTb;select * from v_ScoreTb where courseName='MySQL数据库程序设计';
方案:
create table trigger_CourseTb (courseNo char(6) primary key comment '课程号',courseName varchar(40) not null comment '课程名称',term char(5) comment '开课学期',weekNumber tinyint comment '周学时',credit tinyint comment '学分',courseType char(4) check(courseType in ('选修', '必修')) comment '课程性质', teacher varchar(20) comment '上课教师');delimiter $$ create trigger trigger_coursebefore delete on CourseTbfor each rowbegininsert into trigger_CourseTbselect * from CourseTbwhere courseNo=old.courseNo;end;$$
用ER图可以更方便的展示数据库结构,请自行了解。
来源地址:https://blog.csdn.net/AdamCY888/article/details/129466366
--结束END--
本文标题: MySQL 案例-教学管理信息系统
本文链接: https://www.lsjlt.com/news/551772.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-06-06
2024-06-06
2024-06-05
2024-06-04
2024-06-04
2024-06-03
2024-06-03
2024-06-03
2024-06-04
2024-06-03
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0