课程名称:
数据库原理实验
实验类型:
验证型
实验名称
数据库查询
学时
4学时
实验目的:
使学生掌握SQL Server Query Analyzer的使用方法,加深对SQL和T-SQL语言的查询语句的理解。熟练掌握表的基本查询,连接查询和嵌套查询,以及掌握数据排序和数据分组的操作方法。
实验原理:
SELECT [ALL|DISTINCT] <目标列表达式>[,<目标列表达式>]…
FROM <表名或视图名>[,<表名或视图名>]…
[WHERE <条件表达式>]
[GROUP BY <列名1> [HAVING <条件表达式>]]
[order by <列名2> [ASC|DESC]];
实验方法:
将查询需求用T-SQL语言表示;在SQL Server Query Analyzer的输入区中输入T-SQL查询语句;设置 Query Analyzer的结果区为Standard Execute(标准执行)或Execute to Grid(网格执行)方式;发布执行命令,并在结果区中查看查询结果;如果结果不正确,要进行修改,直到正确为止。
实验内容:
分别用带DISTINCT和不带DISTINCT关键字的SELELCT在student中进行查询.
带distinct:
Select class_id
from student
不带distinct:
select distinct class_id
from student
将teacher表中各教师的姓名、教工号及工资按95%发放的信息,并将工资按95%发放后的列名改为‘预发工资’
select teacher_id,teacher_name,salary*
as 预发工资
from teacher
查询course表中所有学分大于2并且成绩不及格的学生的信息.
select distinct student.*
from student,course,sc
where =
and =
and >2
and <60
查询学分在4~8之间的学生信息.(用between..and和复合条件分别实现)
select distinct student.*
from student,course,sc
where =
and =
and
between 4 and 8
从student_course表中查询出学生为“g9940201”,“g9940202”的课程号、学生号以及学分,并按学分降序排列(用in实现)
select *
from sc,course
where student_id in('g9940201','g9940202')
and =
order by desc
从teacher表中分别检索出姓王的教师的资料,或者姓名的第2个字是远或辉的教师的资料
select *
from teacher
where teacher_name
like '王%'
or teacher_name
like'_远%'
or teacher_name
like '_辉%'
查询每个学生及其选修课情况
select student_name,course_name
from student, sc,course
where =
and =
以student表为主体列出每个学生的基本情况及其选课情况,如果学生没有选课,只输出其基本情况
select student.*,course.*
from student join sc
on =
left join course
on =
查询选修dep04_s001号课程且成绩在80分以上的学生信息。(分别用连接,in和exists实现)
连接:
select stud
数据库1数据查询 来自淘豆网www.taodocs.com转载请标明出处.