实验项目名称: 存储过程和触发器 实验学时: 2
同组学生姓名: 实验地点:
实验日期: 母女俩 实验成绩:
批改教师: 批改时间:
一、实验目的和要求
1、通过对常用系统存储过程的使用,了解存储过程的类型;
2、通过创建和执行存储过程,了解存储过程的基本概念,掌握使用存储过程的操作技巧和方法;
3、通过对已创建的存储过程的改变,掌握修改、删除存储过程的技巧;
4、了解触发器的基本概念,理解触发器的功能;
5、掌握创建、修改和删除和使用触发器的操作方法。
二、实验设备、环境
设备:奔腾Ⅳ或奔腾Ⅳ以上计算机;
环境:WINDOWS 2000 SERVER或WINDOWS 2003 SERVER、SQL Server 2005中文版。
川沙城三、实验步骤
1、根据题目要求熟悉SQL Server 2005的各种管理工具;
2、分析题意,重点分析题目要求并给出解决方法;
3、按题目要求完成实际操作任务,并将相关文档资料保存在以自己学号命名的文件夹中;
4、提交完成的实验结果。
四、实验内容
一、存储过程的类型。
1、使用sp_helptext查看byroyalty存储过程的文本,该存储过程在数据库pubs中。
sp_helptext byroyalty;
标题级别
二、创建与执行存储过程
1、在MyDB中创建存储过程proc_1,要求实现如下功能:产生学分为4的课程学生选课情况列表,其中包括课程号、课程名、学分、学号、姓名、专业、性别等。并调用此存储过程,显示执行结果。
create or replace PROCEDURE proc_1
as cno char(4);cname varchar(16);credit int;sno char(8);sname varchar(10);specially varchar(3);x char(2);
begin
lect couro,dit,student.sno,student.sname,student.x,class1.specially
into cno,cname, credit,sno,sname,x, specially
写人的作文结尾
from cour,student,grade,class1
where couro = gradeo and student.sno = grade.sno and class1.clsno = student.
clsno dit = 4;
end proc_1;
2、在MyDB中创建存储过程proc_2,要求实现如下功能:输入专业名称,产生该专业学生的选课情况列表,其中包括专业、学号、姓名、课程号、课程名、成绩、学分等。并调用此存储过程,显示“计算机应用”专业学生的选课情况列表。
create or replace
PROCEDURE proc_2(spec in varchar)
as cno char(4);cname varchar(16);credit int;sno char(8);sname varchar(10);specially varchar(3);score numeric(4,2);
BEGIN
lect class1.specially,student.sno,student.sname,couro,
courame,grade.dit
into specially,sno,sname,cno,cname,score,credit
from class1,student,cour,grade
where student.sno = grade.sno and couro = gradeo
and student.clsno = class1.clsno and class1.specially = spec;
end;
3、在MyDB中创建存储过程proc_3,要求实现如下功能:输入学生学号,根据该学生所选课程的总学分显示提示信息,如果总学分<9,则显示“此学生学分不足!”,否则显示“此学生学分已足!”,并调用此存储过程,显示“19920102”学生的总学分情况。
create procedure proc_3(@sno1 char(8))
as declare
@Total tinyint;
begin
脚指甲凹凸不平lect @Total=sum(三明治的英文cour.credit)
from cour,student,grade
where student.sno = grade.sno and cour.cno = grade.cno and student.sno = @sno1
if @Total < 9
print '此学生学分不足'
el
print '此学生学分已足'
大雁飞end;
exec proc_3 19920106
三、修改存储过程
1、对MyDB中已创建的存储过程proc_1进行修改,要求在显示列表中增加班级字段,即产生学分为“4”的课程学生选课情况列表,其中包括课程号、课程名、学分、学号、姓名、专业、班级、性别等.
alter PROCEDURE proc_1
俬怎么读
as cno char(4);clsname char(10);cname varchar(16);credit int;sno char(8);sname varchar(10);specially varchar(3);score numeric(4,2);
BEGIN
lect couro,dit,student.sno,student.sname,student.x,class1.specially,class1.claname