当前位置:文档之家› 数据库视图和索引游标实验报告

数据库视图和索引游标实验报告

on =
b.
select ID,name,
(select count(course_id) as bianhao
from teaches where =
from instructor
c.
select ,
from teaches,instructor
where = 'Spring' and =2010 and =
(select ID from student where = )
实验四:
1.
begin tran
declareupsa cursor for
select *
from instructor
where dept_name = 'Comp. Sci.'
open upsa
fetch next from upsa
实验三:
1.执行结果如下:
命令成功完成。
命令成功完成。
命令成功完成。
命令成功完成。
实验四:
1.
命令成功完成。
2.命令成功完成。
实验三:
1.
Create view Einstein_student
As
Select distinct , ,,,
From student,instructor,advisor
Where = 'Einstein' and ='22222' and =
2.
a.
select *
from instructor left outer join teaches
update instructor
set salary = salary *
where current of upsa
while @@FETCH_STATUS =0
begin
fetch next from upsa
update instructor
set salary = salary*
where current of upsa
评价教师签名:
一、实验目的
1.学习并掌握视图的创建、使用、修改和删除。
2.学习并掌握索引的创建和使用。
3.学习并掌握数据库的连接操作。
4.掌握transact-SQL的变量定义方法。
5.了解并掌握游标的定义。
6.了解并掌握声明、打开、提取、关闭和释放游标。
7.了解并掌握使用游标修改数据。
二、实验项目内容
《数据库系统》实验报告
年级、专业、班级
2011级计科4班
姓名
XX
实验题目
视图和索引游标
实验时间
2013/10/25
实验地点
A主414
实验成绩
实验性质
□验证性□设计性□综合性
教师评价:
□算法/实验过程正确;□源程序/实验内容提交□程序结构/实验步骤合理;
□实验结果正确;□语法、语义正确;□报告规范;
其他:
end
commit tran
close upsa
deallocate upsa
2.
declare student cursor For
select distinct ,,,
from instructor,student,advisor
where ='Einstein' and = and =
for read only
实验三:
1.(改编自.)建立视图,它给出了名叫Einstein的教师所教的所有学生的信息,保证结果中没有重复。
2.用SQL查询语句写出下面的查询。
a.显示所有教师的列表,列出他们的ID,姓名以及所讲授的课程段的编号。对于没有讲授任何课程段的教师,确保将课程段的编号显示为0。在你的查询中应该使用外连接,不能使用标量子查询。
declare @id char(20),@name char(20),@dept_name char(20) ,@tot_cred char(20)
open student
fetch next From student into @id ,@name,@dept_name ,@tot_cred
WHILE @@FETCH_STATUS = 0
b.使用标量子查询,不能使用外连接写出上述查询。
c.显示2010年春季开设的所有课程的列表,包括讲授教程段的教师的姓名。如果一个课程段有不止一位教师讲授,那么有多少位教师,此课程段在结果中就出现多少次。如果一个课程段没有任何教授,他也要出现在结果中,相应的教师名设置为“—”。
d.显确处理没有教师的系。
不使用SQL外连接运算也可以在SQL中计算外连接表达式。为了阐明这个事实,不使用外连接表达式重写下面的SQL查询。
a.select *from student natural left outer join takes
* from student natural full outer join takes
from student
where not exists
(select ID from takes where = )
union
(select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL
from takes
where not exists
from student where not exists
(select ID from takes where =
b.
(select *
from student natural join takes)
union
(select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL
BEGIN
PRINT @id +@name+@dept_name+@tot_cred
fetch next From student into @id ,@name,@dept_name ,@tot_cred
END
close student
DEALLOCATE student
四、实验结果及分析和(或)源程序调试过程
d.
select *
from department left outer join instructor
on =
3.
a.
select *
from student natural join takes
union
select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL
实验四:
1.用游标的方式完成,使用大学模式,给.系的每位老师涨10%的工资。
2.(改编自.)用游标的方式完成,使用大学模式,找出名叫Einstein的教师所教的所有学生的表示,保证结果中没有重复,并将他们赋值给变量student1、student 2、、、student n
三、实验过程或算法(源程序)
相关主题