南昌航空大学实验报告二 00年月日课程名称: 数据库概论实验名称: 数据库存储过程与触发器班级: 122031 姓名: 同组人: 指导教师评定: 签名: 一、实验环境 indows2000 或以上版本; 2. SQLServer 2005 。二、实验目的熟悉不同数据库的存储过程和触发器,重点实践 SQL Server2005 ,掌握 SQL Server2005 中有存储过程与触发器的相关知识。三、实验要求完成实验指导书中 p115-7 和 p132 -4。四、实验步骤及参考源代码 1. 创建与执行存储过程 create procedure C_P_Proc as select distinct a,pna,num from paper,customer,cp where o=o and = a=' 李涛' a=' 钱金浩' go execute C_P_Proc 2. 删除存储过程 drop procedure C_P_Proc 3. 创建插入触发器 create trigger TR_PAPER_I ON PAKER12203125 FOR INSERT AS DECLARE ***@appr float DECLARE ***@apno int SELECT ***@appr=ppr,***@apno=pno from inserted begin if ***@appr<0 or ***@appr is null begin raiserror(' 报纸的单价为空或小于!',16,1) update paper set ppr=10 where =***@apno end end 4. 创建删除触发器 create Trigger TR_PAPER_D on PAKER12203125 after delete as declare ***@ipno char(6) declare ***@icount int; select ***@icount= count(*) from deleted,cp where = if ***@icount>=1 begin select ***@ipno=pno from deleted raiserror(' 级联删除 cp 表中的数据',16,1) delete from cp where =***@ipno end 5. 创建修改触发器 create trigger TR_PAPER_U ON PAKER12203125 for update as declare ***@ippr float select ***@ippr=ppr from inserted if ***@ippr<0 or ***@ippr is null beg
数据库存储过程与触发器实验报告 来自淘豆网m.daumloan.com转载请标明出处.