触发器

--新增Customer表后执行下面触发器tgr_Customer_Insert

create  trigger   tgr_Customer_Insert
on  Customer
after insert
as
begin
declare @cCusCode varchar(20)
select @cCusCode=cCusCode from inserted--获取insert后的客户编码
update Customer set cCusSAProtocol=cCusDefine2,cCusRegCode=cCusDefine1 where cCusCode=@cCusCode
end

--删除student表某一条数据后执行下面触发器  select * from deleted 当前删除的表记录信息(字段跟原表一样) 
create trigger trig_student_delete on student after delete as begin select stu_id as 已删除的学生编号,stu_name stu_gender,stu_age from deleted end;
---------------------------------查询触发器------------------------------------------------------------
SELECT * FROM SYSOBJECTS WHERE XTYPE='TR' AND parent_obj = OBJECT_ID('Customer') 查询Customer表所有触发器
-----------------------修改触发器---------------------------------
alter trigger   tgr_Customer_Insert 
on  Customer
after insert
as
begin
declare @cCusCode varchar(20)
select @cCusCode=cCusCode from inserted--获取insert后的客户编码
update Customer set cCusSAProtocol=cCusDefine2,cCusRegCode=cCusDefine1 where cCusCode=@cCusCode
end



------------恢复内容结束------------

posted on 2022-03-15 09:06  八度空间  阅读(80)  评论(0编辑  收藏  举报

导航