1 / 3
文档名称:

实验四--触发器的使用.doc

格式:doc   大小:17KB   页数:3页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

实验四--触发器的使用.doc

上传人:qiang19840906 2020/10/16 文件大小:17 KB

下载得到文件列表

实验四--触发器的使用.doc

相关文档

文档介绍

文档介绍:实验四触发器的使用4实验目的1、理解触发器基本概念。2、掌握触发器定义及其触发。3、了解触发器调试。4、理解触发器作用。实验内容1、定义一个触发器,完成及时计算所有供应商供应零件总数量。`createorreplacetriggert1_spjafterinsertordeleteorupdateonspjdeclarecursorcur_1isselectsno,sum(qty)assumqtyfromspjgroupbysno;beginforcurincur_1loopupdatessetsqty==;endloop;endt1_spj;insertintospjvalues('S5','P6','J4',700);2、定义触发器,实现实体完整性(以s表供应商代码sno为例)。%type;v_countnumber;cursorcur_snoisselectsnofromsgroupbysnohavingcount(*)>1;beginselectcount(*)intov_countfromswheresnoisnull;ifv_count>0thenraise_application_error(-20008,'主码sno不能取空值');endif;opencur_sno;fetchcur_snointov_sno;ifcur_sno%foundthenraise_application_error(-20012,'主码sno不能重复');endif;endt2_spj;insertintoS(SNO,SNAME,STATUS,CITY)values('S1','竟仪',20,'天津');3、定义触发器,实现参照完整性(以spj表供应商代码sno参照s表供应商代码sno为例)。--当在SPJ表插入数据时,如果S,P,J表不存在相应的记录时,则插入失败createorreplacetriggertr1_spjbeforeinsertorupdateofsno,pno,jnoonspjforeachrowdeclarev_count1number;v_count2number;v_count3number;beginselectcount(*)intov_count1fromswheresno=:;ifv_count1<1thenraise_application_error(-20001,'供应商编号为'||to_char(:)||'不存在');endif;selectcount(*)intov_count2frompwherepno=:;ifv_count2<1thenraise_application_error(-20002,'供应商编号为'||to_char(:)||'不存在');endif;selectcount(*)intov_count3fromjwherejno=:;ifv_count3<1thenraise_application_error(-20003,'供应商编号为'||to_ch