1. 首页
  2. 文档大全

MySQL数据库原理及应用答案实训题.docx

上传者:比*** 2022-07-27 02:56:59上传 DOCX文件 27.50KB
MySQL数据库原理及应用答案实训题.docx_第1页 MySQL数据库原理及应用答案实训题.docx_第2页 MySQL数据库原理及应用答案实训题.docx_第3页

《MySQL数据库原理及应用答案实训题.docx》由会员分享,可在线阅读,更多相关《MySQL数据库原理及应用答案实训题.docx(11页珍藏版)》请在文档大全上搜索。

1、课后习题名称:学生选课管理系统(stuCourse)/*/*工程3*/*为学生选课管理系统创立名为“stucourse”的数据库。*/ create database stucourse;/*为学生选课管理系统数据库(stucourse)创立表,表结构如下,字段名参考表3-26表3-30。(1)创立学生表,学生student (学号,姓名,性别,年龄,系别)。(2)创立教师表,教师teacher (教师编号,姓名,职称,工资,系别,课程号)。(3)创立课程表,课程courseinfo (课程编号,课程名称,教材编号,测试时间,系别)。(4)创立选课表,选课scourse (学号,分数,课程编号

2、,教师编号)。(5)创立教材表,教材bookinfo (教材编号,教材名称,出版社,价格,数量)*/create table student(sid char(10) not null primary key,sname char(8) not null, sex char(2) null, age int null,dept varchar(20) null)create table teacher(tid char(10) not null primary key, tname char(8) not null, tpassword char(8) not null, title varc

3、har(20), salary float, dept varchar(20), cid char(10)create table courseinfocid char(10) primary key not null, cname varchar(20), ebook char(10),2)、更新数据updatescourse set credit=casewhen cid='C4' then 1when cid='C3' then 2when cid='C2' then 3when cid='Cl' then 4 endsel

4、ect * from scourse3)、输出语句Declare var char(4)select var = (select distinct credit from scourse where cid='Cl')if var>lif var <4print'学分在23之间,elseprint,学分大于4,elseprint '学分小1分,1*3.调整课程的学分,对学分为2的调整为3,对学分为1的调整为2,其他的学分调整为 lo */update scourseset credit=casewhen credit=2 then credit+1w

5、hen credit=l then credit+1 else 1end select credit from scourse/*4.事务的使用。在SC表中,学号为“1001”学生的平均成绩如果小于75,那么该学生的每门成绩以5%的比例提高,当平均成绩大于等于75,或者所有课程都及格时, 终止操作。*/*5,游标的使用。某一选修课程考试结束后,教师录入学生的成绩后,出于某些原因(如试 卷本身可能存在缺陷),老师需要将该课程所有的学生成绩加5分(但是总分不能超过100分),修改后的成绩如果 介于55分59分之间,将这些学生的成绩修改为60分。*/*在SC表中,学号为1001 学生的平均成绩如果小

6、于75,那么该学生的每门成绩以5%的 比例提高,当平均成绩大于等于75或者所有课程都及格时,终止操作。*/*(分析:此题可以分四个步骤,请根据以下提示完成此题.)1)、为了不影响scourse表的其他应用,首先将学号为1001的学生的所有信息复制到新表 the scourse*/select *into the_scoursefrom scoursewhere sid='1001'/*2)、查询复制后表the_sc中的数据及平均成绩*/select * from the_scourseselect avg(score) from the_scourse/*3)、更新表the_s

7、course中的数据*/while(select avg(score)from the_scourse)75beginupdate the_scourse set score=score*1.05if(select min(score)from the_scourse)>=60 breakend/*4)、查询更新后表the_scourse中的数据及平均成绩*/select * from the_scourseselect avg(score) from the_scourse/*工程 6*/.在stucourse数据库中创立一个的触发器,该触发器不允许的courseinfo表中的cnam

8、e列 进行更新。1 .在stucourse数据库中创立一个触发器,当学生选课时,计算已选的课程门数,超过5门 不允许进行选课操作。/*工程 7*/.在stucourse数据库中创立新视图v_score_avg。要求计算每个同学的选课成绩的平均分。1 .在stucourse数据库中使用CREATE INDEX语句为表stu创立一个非聚集索引,索引字段 s_name,索引名为 IX_STUDENT_name。2 .在stucourse数据库中为表course info创立一个复合索引,按照cname为降序,ctest为升 序进行排序。ctest datetime, dept varchar(lO)

9、 ) create table bookinfo(bid char(10) primary key, bname varchar(30), bpublish varchar(30), bprice double, quantity int)create table scourse(sid char(10) not null, score float null, cid char(5) null, tid char(10)/*向上述表中插入数据*/ insert into student values(1001 :宋江男,'25','计算机系)(,3002丁 张明一蜕网&

10、#39;生物系'),(,1003李小鹏:,男,26。计算机系,),(1004,嘟冬匚1 女,,'25',计算机系)(,4005丁李小红:'女'27、'工商管理)(50067赵紫月)女,'24','外语系');insert into teacher values('3102', 1 李明,初级'2500',,计算机系,,'C1'),(3108:,黄小明,初级)'4000',生物系)'C3'),('4105',张小红,“&#

11、39;中级J'3500','工商管理。('5102', 1 宋力月,1高级)'3500',物理系,,C4'),(3106', 1赵明阳,初级'1500',地理系:'C2'),(,71081, 1 张丽一,高级J'3500',生物系,'C3'),('9103', ,王彬,'高级)'3500',计算机系,,'ci'LC7ior,,王力号,初级'1800',1生物系:'Cl');


文档来源:https://www.renrendoc.com/paper/212732828.html

文档标签:

下载地址