数据库练习(参考答案).doc

上传人:苏美尔 文档编号:5656131 上传时间:2020-07-20 格式:DOC 页数:5 大小:29.50KB
返回 下载 相关 举报
数据库练习(参考答案).doc_第1页
第1页 / 共5页
数据库练习(参考答案).doc_第2页
第2页 / 共5页
数据库练习(参考答案).doc_第3页
第3页 / 共5页
数据库练习(参考答案).doc_第4页
第4页 / 共5页
数据库练习(参考答案).doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

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

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

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

3、radeXKLB9512101c0190必修9512101c0286选修9512101c06必修9512102c0278选修9512102c0466必修9521102c0182选修9521102c0275选修9521102c0492必修9521102c0550必修9521103c0268选修9521103c06必修9531101c0180选修9531101c0595必修9531102c0585必修题1:查询没有选修课程“c01”的学生姓名和所在系。答案:select sname,sdept from student where sno not in (select sno from sc wh

4、ere 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)。答案:alter table sc modify(XKLB varchar2 (6);题4:删除Course表的Period列。答案:alter table course drop column period

5、;题5:删除计算机系不及格学生的选课记录。答案:delete from sc where grade60 and sno in (select sno from student where sdept=计算机系); 题6:查询全体学生的学号与姓名。答案:select sno,sname from student;题7:查询全体学生的姓名,学号和所在系。答案:select sname,sno,sdept from student;题8:查询全体学生的记录。答案:select * from student;题9:查询全体学生的姓名及其出生年份。答案:select sname,2014-sage f

6、rom student;或select sname,(to_char(sysdate,YYYY)-sage) from student;题10:查询全体学生的姓名和出生年份,比在出生年份列前加入一个列,此列的每行数据均为“Year of Birth”常量值。答案:select sname,Year of Birth,(to_char(sysdate,YYYY)-sage) from student;题11:在选课表(SC)中查询有哪些学生选修了课程,并列出学生的学号。答案:select distinct sno from sc;题12:查询计算机系全体学生的姓名。答案:select disti

7、nct sname from student where sdept=计算机系;题13:查询所有年龄在20岁以下的学生的姓名及年龄。答案:select sname,sage from student where sage20;题14:查询考试成绩不及格的学生的学号。答案:select distinct sno from sc where grade=20 and sage=23;题16:查询年龄不在2023之间的学生的姓名,所在系和年龄。答案:select sname,sdept,sage from student where sage 23;题17:查询信息系,数学系和计算机系学生的姓名和性

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

9、name like 张% or sname like 李% or sname like 刘%;或者select * from student where 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 w

10、here sname not like 刘%;题23:从学生表中查询学号的最后一位不是2,3,5的学生的情况。答案: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 s

11、no,cno from sc where grade is not null;题26:查询计算机系年龄在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 fr

12、om student , sc where student.sno=sc.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课程的

13、学生的成绩,要求列出学生姓名,课程名和成绩。答案: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:查询与

14、刘晨在同一个系学习的学生的姓名和所在系。答案: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 w

15、here st1.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)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1