文档详情

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

发布:2018-03-07约2.35千字共6页下载文档
文本预览下载声明
实验报告 学院:计信学院 专业: 网络工程 班级:091 姓名 学号 实验组 实验时间 2012-4-28 指导教师 成绩 实验项目名称 实验三:数据库的嵌套查询 实验目的 使学生进一步掌握SQL Server查询分析器的使用方法,加深对SQL语言的嵌套查询语句的理解。 实验内容 在SQL Server查询分析器中使用IN、比较符、ANY或ALL和EXISTS操作符进行嵌套查询操作。 实验环境 (1)硬件条件:个人计算机。 (2)软件条件:Windows 2000NT Server; MS SQL Server 2000。 实验步骤 1、基本操作实验: 用SQL语句表示,在学生选课库中实现其数据嵌套查询操作。 (1)求选修了高等数学的学生学号和姓名。 (2)求C1课程的成绩高于张三的学生学号和成绩。 (3)求其它系中年龄小于计算机系年龄最大者的学生。 (4)求其它系中比计算机系学生年龄都小的学生。 (5)求选修了C2课程的学生姓名。 (6)求没有选修C2课程的学生姓名。 (7)查询选修了全部课程的学生姓名。 (8)求至少选修了学号为“S2“的学生所选修的全部课程的学生学号和姓名。 2、提高操作实验: 对自设计的数据库应用项目的数据查询操作分类,用SQL语句表示其中的简单、连接和嵌套查询,并通过SQL Server查询分析器实现其查询操作。 实验程序 (1)求选修了高等数学的学生学号和姓名。 select Sno,Sname from Student where Sno in ( select Sno from SC where Cno in ( select Cno from Course where Cname=数学 ) ) (2)求数学课程的成绩高于张三的学生学号和成绩。 select Student.Sno,Student.Sname,SC.Grade from Student,SC where ( Student.Sno=SC.Sno and Grade(select Grade from SC where Sno=(select Sno from Student where Sname=张三 )) ) (3)求其它系中年龄小于计算机系年龄最大者的学生。 select * from Student where Sdept!=CS and Sage(select MAX(Sage) from Student where Sdept=CS) (4)求其它系中比计算机系学生年龄都小的学生。 select * from Student where Sdept!=CS and SageALL(select MIN(Sage) from Student where Sdept=CS) (5)求选修了数学课程的学生姓名。 select Student.Sname from Student where Sno in(select Sno from SC where Cno=(select Cno from Course where Cname=数学)) (6)求没有选修数学课程的学生姓名。 select Student.Sname from Student where Sno in(select Sno from SC where Cno!=(select Cno from Course where Cname=数学)) (7)查询选修了全部课程的学生姓名。 select Sname from Student as S where not EXISTS(select * from Course as C where not EXISTS (select * from SC where S.Sno=SC.sno and SC.Cno=C.Cno )) (8)求至少选修了学号为“200215124“的学生所选修的全部课程的学生学号和姓名。 select Sno,Sname from Student as S where not EXISTS(select * from SC as SC1 where SC1.Sno=200215124 and not EXISTS (select * from SC as SC2 where SC2.Sno=S.sno and SC1.Cno=SC2.Cno )) 实验结果 及 分析 Student表 Course表 SC表 1、基本操作实验: (1) (2) (3) (4) (5) (6) (7) (8) 2.提高实验: 查询修了课程5的学生: ①嵌套查询: SELECT Sname F
显示全部
相似文档