全文预览

实验六-存储过程和触发器

上传者:科技星球 |  格式:doc  |  页数:12 |  大小:4390KB

文档介绍
te,其中操作员设定默认值为user,操作时间默认值为系统时间。createtablesc_log(typevarchar(4),st_idvarchar(10),c_novarchar(10),oldscoreint,newscoreint,unamevarchar(10)defaultuser,udatadatetimedefaultgetdate())gocreatetriggertr_scons_c_infoforinsert,updateasifupdate(score)beginif(selectcount(*)fromdeleted)<>0insertintosc_log(type,st_id,c_no,oldscore,newscore)froms_c_info,insertedi,deleteddelseinsertintosc_log(type,st_id,c_no,newscore)select'insert',st_id,c_no,scorefrominsertedendgo在s_c_info表上建立一个触发器tr_updasc,用于监控对成绩的更新,要求更新后的成绩不能比更新前低,如果新成绩低则取消操作,给出提示信息,否则允许更新。createtriggertr_updascons_c_infoafterupdateasdeclare@cj1int,@cj2intif(@cj2<@cj1)beginraiserror('新成绩比老成绩低,取消操作',16,1)rollbacktransactionendgo(三)查看存储过程和触发器的信息1.用sp_help查看以上建立的存储过程和触发器的基本信息sp_helptr_scgosp_helptr_updascgo2.用sp_helptext查看存储过程和触发器的代码sp_helptexttr_scgo

收藏

分享

举报
下载此文档