数据库1数据资料查询.doc
《数据库1数据资料查询.doc》由会员分享,可在线阅读,更多相关《数据库1数据资料查询.doc(15页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、#*实验一实验一 数据库查询数据库查询课程名称:课程名称:数据库原理实验实验类型:实验类型:验证型 实验名称实验名称数据库查询学时学时4 学时实验目的:实验目的: 使学生掌握 SQL Server Query Analyzer 的使用方法,加深对 SQL 和 T-SQL 语言的查询语句的理解。熟练掌握表的基本查询,连接查询和嵌套查询,以及掌 握数据排序和数据分组的操作方法。 实验原理:实验原理: SELECT ALL|DISTINCT , FROM , WHERE GROUP BY HAVING order by ASC|DESC; 实验方法实验方法: 将查询需求用 T-SQL 语言表示;在
2、SQL Server Query Analyzer 的输入区中输 入 T-SQL 查询语句;设置 Query Analyzer 的结果区为 Standard Execute(标准执 行)或 Execute to Grid(网格执行)方式;发布执行命令,并在结果区中查看查 询结果;如果结果不正确,要进行修改,直到正确为止。 实验内容:实验内容: 1.分别用带 DISTINCT 和不带 DISTINCT 关键字的 SELELCT 在 student 中进行 查询.带 distinct:Select class_id from student不带 distinct:select distinct c
3、lass_id from student2.将 teacher 表中各教师的姓名、教工号及工资按 95发放的信息,并将工资 按 95发放后的列名改为预发工资 select teacher_id,teacher_name,salary*0.95 as 预发工资 from teacher3.查询 course 表中所有学分大于 2 并且成绩不及格的学生的信息. select distinct student.* from student,course,sc where student.student_id=sc.student_id and sc.course_id=course.course_i
4、d and course.credit2 and sc.grade80In:select * from student where student_id in(select student_id from sc where course_id=dep04_s001 and grade80)exists:select * from student where exists(select student_id from sc where student.student_id=sc.student_id and course_id=dep04_s001 and grade80)10. 查询所有上计算
5、机基础课程的学生的学号、选修课程号以及分数(分别用连 接,in 和 exists 实现)连接:select sc.* from sc,course where course.course_name=计算机基础 and course.course_id=sc.course_idIn:select student_id,course_id,grade from sc where course_id in(select course_id from course where course_name=计算机基础)exists:select student_id,course_id,grade from
6、 sc where exists(select * from course where course_id=sc.course_id and course_name=计算机基础)11. 查询选修了课程名为“数据库基础”的学生学号和姓名(分别用连接,in 和 exists 实现)连接:select student.student_id,student.student_name from sc,student,course where course.course_name=数据库开发技术 and sc.student_id=student.student_id and course.course_
7、id=sc.course_idIn:select student_id,student_name from student where student_id in(select student_id from sc where course_id=(select course_id from course where course_name=数据库开发技术 ) )exists:select student_id,student_name from student where exists(select * from sc where sc.student_id=student.student_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 数据资料 查询
限制150内