Create TRIGGER [Update_Table] ON [dbo].[Table] FOR UPDATE,Delete AS declare @ChargeCode Varchar(20) if Update(DayBlanceCode) --在这儿判断是否满足条件,满足执行更新操作 begin set nocount on Declare UpdateCount Cursor for select ChargeCode from Inserted Open UpdateCount Fetch Next From UpdateCount into @ChargeCode While @@Fetch_Status=0 begin Update Tableset DayBalanceFlag=1 where ChargeCode=@ChargeCode Fetch Next From UpdateCount into @ChargeCode end Close UpdateCount DealLocate UpdateCount set nocount off end
"(包括对Table1的删除)."是指删除表Table1还是删除里面的数据呢?
可能是我没讲明白,我主要是想终止触发器(包括删除Table1的记录).
begin transaction if not then rollback transactionelse commit transaction
注: 触发器是Table1的.
INSTEAD OF DELETE
as--判断deleted表处理
FOR UPDATE,Delete
AS
declare @ChargeCode Varchar(20)
if Update(DayBlanceCode) --在这儿判断是否满足条件,满足执行更新操作
begin
set nocount on Declare UpdateCount Cursor for
select ChargeCode from Inserted Open UpdateCount
Fetch Next From UpdateCount into @ChargeCode
While @@Fetch_Status=0
begin
Update Tableset DayBalanceFlag=1 where ChargeCode=@ChargeCode Fetch Next From UpdateCount into @ChargeCode
end
Close UpdateCount
DealLocate UpdateCount set nocount off
end
if not then rollback transactionelse
commit transaction