数据库的嵌套查询实验.doc

上传人:PIYPING 文档编号:10765997 上传时间:2021-06-03 格式:DOC 页数:8 大小:123.50KB
返回 下载 相关 举报
数据库的嵌套查询实验.doc_第1页
第1页 / 共8页
数据库的嵌套查询实验.doc_第2页
第2页 / 共8页
数据库的嵌套查询实验.doc_第3页
第3页 / 共8页
数据库的嵌套查询实验.doc_第4页
第4页 / 共8页
数据库的嵌套查询实验.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《数据库的嵌套查询实验.doc》由会员分享,可在线阅读,更多相关《数据库的嵌套查询实验.doc(8页珍藏版)》请在三一文库上搜索。

1、 实验报告一、 实验内容 数据库的嵌套查询实验二、 实验目的进一步掌握SQL Server的使用方法,学会利用Transact-SQL语言表达嵌套查询语句,理解相关的SQL语句。三、 实验内容用Transact-SQL表达嵌套查询操作,包括使用IN、比较符、ANY或ALL和EXISTS等操作符,通过SQL Server查询分析器输入、分析并显示正确结果。四、 实验前准备Courses表:Reports表:Students表:五、 实验结果1) 求选修了高等数学的学生学号和姓名2)求C1课程的成绩高于张三的学生学号和成绩3)求其他系中比计算机系某一学生年龄小的学生4)求其他系中比计算机系学生年龄

2、都小的学生5)求选修了C2课程的学生姓名6)求没有选修C2课程的学生姓名7)查询选修了全部课程的学生的姓名8)求至少选修了学号为“S2”的学生所选修的全部课程的学生学号和姓名六、 主要实验步骤1)求选修了高等数学的学生学号和姓名select sno,snamefrom students awhere sno in( select sno from reports b where sno=a.sno and cno in( select cno from courses where cno=o and cname=高等数学)2) 求C1课程的成绩高于张三的学生学号和成绩select sno,gr

3、adefrom reportswhere cno=1 and grade( select grade from reports where cno=1 and sno=( select sno from students where sname=张三)3)求其他系中比计算机系某一学生年龄小的学生select sno,snamefrom studentswhere sdept计算机 and 2012-year(birthday)any( select 2012-year(birthday) from students where sdept=计算机)4)求其他系中比计算机系学生年龄都小的学生se

4、lect sno 学号,sname 姓名from studentswhere sdept计算机 and 2012-year(birthday)all( select 2012-year(birthday) from students where sdept=计算机)5)求选修了C2课程的学生姓名select snamefrom students awhere exists( select * from reports where cno=2 and sno=a.sno)6)求没有选修C2课程的学生姓名select snamefrom students awhere not exists( se

5、lect * from reports where cno=2 and sno=a.sno)7)查询选修了全部课程的学生的姓名select snamefrom students awhere not exists( select * from courses b where not exists( select * from reports where cno=o and sno=a.sno)8)求至少选修了学号为“S2”的学生所选修的全部课程的学生学号和姓名select distinct sno,snamefrom students awhere not exists( select * f

6、rom reports b where sno=2 and not exists( select * from reports where sno=a.sno and cno=o)七、 实验出现的问题和解决办法出现的问题:查询文件关闭后开启执行出现“对象名无效”错误解决方法:(1)通过鼠标选择可用数据库为Teach数据库,即对象数据库;(2)利用SQL语句“USE Teach”即“USE ”+数据库名称指定对象数据库。注意事项:(1)输入SQL语句时应注意,语句中使用西文操作符号,包括引号、等号、逗号等;(2)选定对象数据库后进行相应的查询。八、 体会与提高运用SQL语言需注意细节问题,例如符号的使用、数据库的使用等。

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

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


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