您好,欢迎来到小侦探旅游网。
搜索
您的当前位置:首页数据库视图和索引-游标实验报告

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

来源:小侦探旅游网


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

《数据库系统》实验报告

年级、专业、班级 实验题目 实验时间 2013/10/25 2011级计科4班 姓名 XX 视图和索引 游标 实验地点 实验性 质 □验证性 □设计性 □综合性 A主414 实验成绩 教师评价: □算法/实验过程正确; □源程序/实验内容提交 □程序结构/实验步骤合理; □实验结果正确; □语法、语义正确; □报告规范; 其他: 评价教师签名: 一、实验目的 1.学习并掌握视图的创建、使用、修改和删除。 2.学习并掌握索引的创建和使用。 3.学习并掌握数据库的连接操作。 4.掌握transact-SQL的变量定义方法。 5.了解并掌握游标的定义。 6.了解并掌握声明、打开、提取、关闭和释放游标。 7.了解并掌握使用游标修改数据。 二、实验项目内容 实验三: 1.(改编自3.1a.)建立视图,它给出了名叫Einstein的教师所教的所有学生的信息,保证结果中没有重复。 2.用SQL查询语句写出下面的查询。

a.显示所有教师的列表,列出他们的ID,姓名以及所讲授的课程段的编号。对于没有讲授任何课程段的教师,确保将课程段的编号显示为0。在你的查询中应该使用外连接,不能使用标量子查询。 b.使用标量子查询,不能使用外连接写出上述查询。 c.显示2010年春季开设的所有课程的列表,包括讲授教程段的教师的姓名。如果一个课程段有不止一位教师讲授,那么有多少位教师,此课程段在结果中就出现多少次。如果一个课程段没有任何教授,他也要出现在结果中,相应的教师名设置为“—”。 d.显示所有系的列表,包括每个系中教师的总数,不能使用标量子查询。确保正确处理没有教师的系。 4.2 不使用SQL外连接运算也可以在SQL中计算外连接表达式。为了阐明这个事实,不使用外连接表达式重写下面的SQL查询。 a.select *from student natural left outer join takes b.select * from student natural full outer join takes 实验四: 1. 用游标的方式完成,3.3a使用大学模式,给Comp.Sci. 系的每位老师涨10%的工资。 2. (改编自3.1a.)用游标的方式完成, 使用大学模式,找出名叫Einstein的教师所教的所有学生的表示,保证结果中没有重复,并将他们赋值给变量student1、student 2、、、student n 三、实验过程或算法(源程序) 实验三: 1. Create view Einstein_student As Select distinct instructor.name, advisor.i_ID,advisor.s_ID,student.ID,student.name From student,instructor,advisor Where instructor.name = 'Einstein' and advisor.i_ID='22222' and advisor.s_ID = student.ID 2.

a. select * from instructor left outer join teaches on instructor.ID = teaches.ID b. select ID,name, (select count(course_id) as bianhao from teaches where teaches.ID=instructor.ID) from instructor c. select teaches.course_id,instructor.name from teaches,instructor where teaches.semester= 'Spring' and teaches.year=2010 and teaches.ID=instructor.ID d. select * from department left outer join instructor on department.dept_name = instructor.dept_name 3. a. select * from student natural join takes union

select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL from student where not exists b. (select * from student natural join takes) union (select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL from student where not exists (select ID from takes where takes.ID = student.ID)) (select ID from takes where takes.ID = student.ID) union (select ID,name,dept_name,tot_cred,NULL,NULL,NULL,NULL,NULL,NULL from takes where not exists 实验四: 1. begin tran declare upsa cursor for select * from instructor where dept_name = 'Comp. Sci.' open upsa fetch next from upsa update instructor (select ID from student where takes.ID = student.ID))

set salary = salary * 1.10 where current of upsa while @@FETCH_STATUS =0 begin fetch next from upsa update instructor set salary = salary * 1.10 where current of upsa end commit tran close upsa deallocate upsa 2. declare student cursor For select distinct student.ID,student.name,student.dept_name, student.tot_cred from instructor,student,advisor where instructor.name='Einstein' and instructor.ID=advisor.i_ID and advisor.s_ID =student.ID for read only 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 BEGIN PRINT @id +@name+@dept_name+@tot_cred fetch next From student into @id ,@name,@dept_name ,@tot_cred END close student DEALLOCATE student

四、实验结果及分析和(或)源程序调试过程 实验三: 1.执行结果如下: 2.a 命令成功完成。

2.b 命令成功完成。 2.c 命令成功完成。

2.d 命令成功完成。 实验四: 1. 命令成功完成。

2.命令成功完成。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- xiaozhentang.com 版权所有 湘ICP备2023022495号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务