数据库练习(参考 答案)

上传人:小** 文档编号:58274916 上传时间:2018-10-28 格式:DOCX 页数:5 大小:18.30KB
返回 下载 相关 举报
数据库练习(参考 答案)_第1页
第1页 / 共5页
数据库练习(参考 答案)_第2页
第2页 / 共5页
数据库练习(参考 答案)_第3页
第3页 / 共5页
数据库练习(参考 答案)_第4页
第4页 / 共5页
数据库练习(参考 答案)_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《数据库练习(参考 答案)》由会员分享,可在线阅读,更多相关《数据库练习(参考 答案)(5页珍藏版)》请在金锄头文库上搜索。

1、根据给出的表结构完成以下题目 表 1-1 Student 表结构 列名说明数据类型约束 Sno 学号字符串,长度为 7主码 Sname 姓名字符串,长度为 10非空 Ssex 性别字符串,长度为 2取男或女 Sage 年龄整数取值 1545 Sdept所在系字符串,长度为 20默认为计算机系表 3-1 Student 表数据 SnoSnameSsex SageSdept9512101李勇男19计算机系 9512102刘晨男20计算机系 9512103王敏女20计算机系 9521101张立男22信息系 9521102吴宾女21信息系 9521103张海男20信息系 9531101钱小平女18数学

2、系 9531102王大力男19数学系 -表 1-2Course 表结构 列名说明数据类型约束 Cno课程号字符串,长度为 10主码 Cname课程名字符串,长度为 20非空 Ccredit学分整数取值大于 0 Semster学期整数取值大于 0 Period学时整数取值大于 0表 3-2 Course 表数据 Cno CnameCcreditSemesterC01 计算机文化学31 C02 VB23C03 计算机网络47 C04 数据库基础66 C05 高等数学82 C06 数据结构54表 1-3 SC 表结构 列名说明数据类型约束 Sno学号字符串,长度为 7主码,引用 Student 的外

3、码 Cno课程名字符串,长度为 10主码,引用 Course Grade成绩整数取值 0100表 3-3 SC 表数据 SnoCno GradeXKLB9512101c01 90必修 9512101c02 86选修 9512101c06 必修 9512102c02 78选修 9512102c04 66必修 9521102c01 82选修 9521102c02 75选修 9521102c04 92必修 9521102c05 50必修 9521103c02 68选修 9521103c06 必修 9531101c01 80选修 9531101c05 95必修 9531102c05 85必修题 1:查

4、询没有选修课程“c01”的学生姓名和所在系。 答案:select sname,sdept from student where sno not in (select sno from sc where cno=C01)select sname,sdept from student,sc where (student.sno=sc.sno) and (sc.sno != “co1”)题 2:为 SC 表添加“选课类别”列,此列的定义为 XKLB char(4)。 答案:alter table sc add(XKLB varchar2(4); 题 3:将新添加的 XKLB 的类型改为 char(6

5、)。 答案:alter table sc modify(XKLB varchar2 (6); 题 4:删除 Course 表的 Period 列。 答案:alter table course drop column period; 题 5:删除计算机系不及格学生的选课记录。 答案: delete from sc where grade=20 and sage 23; 题 17:查询信息系,数学系和计算机系学生的姓名和性别。 答案:select sname,ssex from student where sdept IN (信息系 , 数学系 , 计算机 系); 题 18:查询既不属于信息系,数

6、学系,也不属于计算机系的学生的姓名和性别。 答案:select sname,ssex from student where sdept not in( 信息系,数学系,数学系); 题 19:查询姓“张”的学生的详细信息。 答案:select * from student where sname like 张%; 题 20:查询学生表中姓“张” ,姓“李”和姓“刘”的学生的情况。 答案: select * from student where sname like 张% or sname like 李% or sname like 刘%; 或者 select * from student whe

7、re sname like 张李刘%; /错误 题 21:查询名字中第 2 个字为“小”或“大”字的学生的姓名和学号。 答案: select sname ,sno from student where sname like _小% or sname like _大%; 或者 select sname ,sno from student where sname like _小大%; 题 22:查询所有不姓“刘”的学生。 答案:select * from student where sname not like 刘%; 题 23:从学生表中查询学号的最后一位不是 2,3,5 的学生的情况。 答案:

8、 select * from student where sno not like %2 and sno not like %3 and sno not like %5;或者 select * from student where sno not like %235; /错误 题 24: 查询无考试成绩的学生的学号和相应的课程号。 答案:select sno,cno from sc where grade is null; 题 25:查询所有有考试成绩的学生的学号和课程号。 答案:select sno,cno from sc where grade is not null; 题 26:查询计算

9、机系年龄在 20 岁以下的学生的姓名。 答案:select sname from student where sdept = 计算机系 and sage 3; 题 38:查询选课门数等于或大于 4 门的学生的平均成绩和选课门数。 答案:select sno,avg(Grade),count(*) from sc group by sno having count(*)= 4; 题 39:查询每个学生的情况及其选课的情况。 答案: select student.sno,sname,ssex,sage,o,cn.grade from student , sc where student.sno=s

10、c.sno;题 40:去掉例 38 中的重复列。 答案: select distinct avg(grade),count(sno) 选课门数 from sc group by sno having count(sno) 3;题 41:查询计算机系学生的选课情况,要求列出学生的名字,所修课的课程号和成绩。 答案: select student.sname,o,sc.grade from sc left join student on student.sno=sc.sno where sc.sdept=计算机系; 题 42:查询信息系选修 VB 课程的学生的成绩,要求列出学生姓名,课程名和成绩。

11、 答案: select student.sname,o,sc.grade from student join sc on student.sno=sc.sno join course on o=o where sc.sdept=信息系 and ame=VB; 题 43:查询所有选修了 VB 课程的学生的情况,要求列出学生姓名和所在的系。 答案:select student.sname,sc.sdept from student join sc on student.sno=sc.sno join course on o=o where ame=VB;题 44:查询与刘晨在同一个系学习的学生的姓

12、名和所在系。 答案: select s2.sname, s2.sdept from student s1 , student s2 where s1.dept = s2.dept and s1.sname = 刘晨 and s2.sname != 刘晨; 题 45:查询学生的选课情况,包括选修课程的学生和没有修课的学生。 答案:select * from student left join sc on student.sno=sc.sno; 题 46:查询与刘晨在同一个系的学生。 答案:select sno,sname from student st1, student st2 where s

13、t1.sno = st2.sno and st2.sname=刘 晨; 题 47:查询成绩大于 90 分的学生的学号和姓名。 答案:select sno,sname,grade from student,sc where grade in (select grade from sc where grade90)题 48:查询选修了“数据库基础”课程的学生的学号和姓名。 答案: select sno,sname from student where sno in (select sno from sc where cno in (select cno from course where cname=数据库基础) 题 49:查询选修了课程“c02”且成绩高于次课程的平均成绩的学生的学号和成绩。 答案: select sno,grade from sc where grade ( select AVG(grade) from sc where cno=C02 group by cno)题 50:查询选修了课程“c01”的学生姓名。 答案: select sname from student where sno in (select sno from sc where cno=C01)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号