BX121028俞佳星实验六

上传人:飞*** 文档编号:16376603 上传时间:2017-11-07 格式:DOC 页数:4 大小:1.21MB
返回 下载 相关 举报
BX121028俞佳星实验六_第1页
第1页 / 共4页
BX121028俞佳星实验六_第2页
第2页 / 共4页
BX121028俞佳星实验六_第3页
第3页 / 共4页
BX121028俞佳星实验六_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《BX121028俞佳星实验六》由会员分享,可在线阅读,更多相关《BX121028俞佳星实验六(4页珍藏版)》请在金锄头文库上搜索。

1、电子信息学院实 验 报 告 书课 程 名 : 数据库原理及应用 题 目: 实验六 存储过程及触发器 实验类别 【设计】 班 级: BX1210 学 号: 28 姓 名: 俞佳星 评语:实验态度:认真( ) 一般( ) 较差( )实验结果:正确( ) 部分正确( )错( )实验理论:掌握( ) 熟悉( ) 了解( ) 生疏( )操作技能:较强( ) 一般( ) 较差( )实验报告:较好( ) 一般( ) 较差( )成绩: 指导教师: 批阅时间: 年 月 日 数据库原理及应用实验报告 - 1 1实验目的(1)掌握 SQL Server 编程结构;(2)掌握数据存储过程及触发器使用;2实验内容与步骤

2、:对 teachingSystem 数据库,编写存储过程,完成下面功能:1使用 T-SQL 语句创建存储过程1)创建不带参数存储过程(1)创建一个从 student 表查询学号为 1202 学生信息的存储过程 proc_1,其中包括学号、姓名、性别、出生日期、系别等;调用过程 proc_1 查看执行结果。use teachingsystemgocreate proc proc_1asselect stu_id,name,sex,birthday,dept_idfrom studentwhere stu_id=1202exec proc_1(2)在 teachingSystem 数据库中创建存储

3、过程 proc_2,要求实现如下功能:查询学分为 4 的课程学生选课情况列表,其中包括学号、姓名、性别、课程号、学分、系别等。调用过程 proc_2查看执行结果。use teachingsystemgocreate proc proc_2asselect A.stu_id,name,sex,B.course_id,A.totalscore,B.dept_idfrom student A,course B,student_teacher_course Cwhere A.stu_id=C.stu_id and C.course_id=B.course_id and A.totalscore=590

4、exec proc_22)创建带参数存储过程创建一个从 student 表中按学生学号查询学生信息的存储过程 proc_3.其中包括:学号、姓名、性别、出生日期、系别等。查询学号通过执行语句中输入。use teachingsystem 数据库原理及应用实验报告 - 2 gocreate proc proc_3sno char(6)asselect stu_id,name,sex,birthday,dept_idfrom student where stu_id=snouse teachingsystemgoexec proc_312123)创建带输出参数存储过程创建存储过程,比较两个学生的实际

5、总分,若前者高就输出 0,否则输出 1use teachingsystemgocreate proc proc_4(id1 char(6),id2 char(6),result int out)asbegindeclare sr1 int,sr2 intset sr1=(select totalscore from student where stu_id=id1)set sr2=(select totalscore from student where stu_id=id2)if sr1sr2set result=0elseset result=1enddeclare result inte

6、xec proc_41201,1202,result outputselect result2使用 T-SQL 语句查看、修改和删除存储过程(1)查看存储过程 proc_1 定义Exec sp_helptext proc_1 数据库原理及应用实验报告 - 3 (2)删除存储过程 proc_1Drop proc proc_13使用 T-SQL 语句实现触发器定义。(1)为表 student_teacher_course 创建一个插入触发器,当向表 student_teacher_course 中插入一条数据时,通过触发器检查记录的 stu_id 值在表 student 中是否存在,若不存在,则取

7、消插入操作,并检查 course_id 在表 course 中是否存在,若不存在也取消插入操作。use teachingsystemgocreate trigger credit_insert on student_teacher_coursefor insert,updateasif(select stu_id from inserted)not in (select stu_id from student)beginrollbackendif(select course_id from inserted)not in (select course_id from course)beginrollbackendinsert into student_teacher_course(course_id,teacher_id,stu_id,score)values(100001,30102,1205,90)3.分析与实验体会在本次试验中我通过实际的实验操作,并结合课堂上所学习的内容。我们掌握了 SQL Server 编程结构还掌握数据存储过程及触发器使用。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号