数据库练习(参考答案)_第1页
数据库练习(参考答案)_第2页
数据库练习(参考答案)_第3页
数据库练习(参考答案)_第4页
数据库练习(参考答案)_第5页
免费预览已结束,剩余6页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

根据给出的表结构完成以下题目表 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-2course表结构列名说明cno课程号数据类型字符串,长度为10约束主码精品资料表 3-2 course表数据cno cnameccreditsemester表 1-3 sc表结构列名说明数据类型约束grade成绩整数取值 0100cname课程名字符串,长度为20非空ccredit学分整数取值大于0semster学期整数取值大于0period学时整数取值大于0c01计算机文化学31c02vb23c03计算机网络47c04数据库基础66c05高等数学82c06数据结构54sno学号字符串,长度为7主码,引用student的外码cno课程名字符串,长度为10主码,引用course表 3-3 sc表数据snocno gradexklb 9512101c01 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:查询没有选修课程“ c01 ”的学生姓名和所在系。答案: selectsname,sdeptfromstudentwheresnonotin (selectsnofromsc where cno=c01)select sname,sdept from student,scwhere(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:删除计算机系不及格学生的选课记录。答案:deletefrom 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 from 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 distinct sname from studentwhere 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 :查询信息系,数学系和计算机系学生的姓名和性别。答案: 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 sname 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 where 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 sno,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 snohaving count(*)= 4;题 39 :查询每个学生的情况及其选课的情况。答案:select student.sno,sname,ssex,sage,o,cn.grade from student, sc where student.sno=sc.sno;题 40 :去掉例38 中的重复列。答案:selectdistinctavg(grade),count(sno)选 课 门数fromscgroupbysnohavingcount(sno)3;题 41 :查询计算机系学生的选课情况,要求列出学生的名字,所修课的课程号和成绩。答案:select student.sname,o,sc.grade from sc left join student on student.sno=sc.snowhere sc.sdept=计算机系 ;题 42 :查询信息系选修vb 课程的学生的成绩,要求列出学生姓名,课程名和成绩。答案:selectstudent.sname,o,sc.gradefromstudentjoinscon student.sno=o=owheresc.sdept=信息系ame=vb;题 43 :查询所有选修了vb 课程的学生的情况,要求列出学生姓名和所在的系。答案:selectstudent.sname,sc.sdeptfromstudentjoinsconstudent.sno=sc.snojoin course on o=o where ame=vb;题 44 :查询与刘晨在同一个系学习的学生的姓名和所在系。答案:select s2.sname, s2.sdept from student s1 , student s2 where s1.dept = s2.dept ands1.sname = 刘晨 and s2.sname != 刘晨 ;题 45 :查询学生的选课情况,包括选修课程的学生和没有修课的学生。答案: select * from student left join sc on student.sno=sc.sno;题 46 :查询与刘晨在同一个系的学生。答案: selectsno,snamefromstudentst1,studentst2wherest1.sno=st2.snoand 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 (selectcno from course where cname=数据库基础 )题 49 :查询选修了课程“ c0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论