如何调试触发器 [英] How to Debug Trigger

查看:71
本文介绍了如何调试触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[leave] ON [dbo].[attLeaveApplication]
AFTER UPDATE

AS 
declare @leaveAppId as numeric
declare @leaveId as numeric
declare @empid as varchar
declare @duration as numeric
declare @leavetype as varchar
declare @OP as numeric

select @leaveAppId=[LeaveAppId],@empid=[EmpID],@duration=[ApprDuration],@leaveId=[LeaveId] from inserted where [ApprFlag]=1

select @leavetype=[LeaveType] from attLeaveTypeMaster where [LeaveId]=@leaveId


if @leavetype='CL'
Begin
select @OP=[CLCL] from attLeaveTransaction where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
set @OP = @OP - @duration
update attLeaveTransaction set [CLCL]=@OP where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
END
if @leavetype='PL'
Begin
select @OP=[PLCL] from attLeaveTransaction where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
set @OP = @OP - @duration
update attLeaveTransaction set [PLCL]=@OP where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
END
if @leavetype='SL'
Begin
select @OP=[SLCL] from attLeaveTransaction where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
set @OP = @OP - @duration
update attLeaveTransaction set [SLCL]=@OP where [EmpId]=@empid and DATEPART(Month,[Month])=DATEPART(Month,GetDate())
END


使用此触发器来帮助我.执行更新时不会触发.


您能告诉我如何在sql server中调试触发器吗?


Help Me with this trigger. It is not triggered when update is performed.


Can u tell me how can i debug trigger in sql server?

推荐答案

好吧,看看触发器查询和AFAICU,您是否需要更新触发器或INSERT触发器? ?

可能是您想要的,在表"attLeaveApplication"获得应用程序的那一刻,您想使用此触发器.如果是这样,则需要使用INSERT触发器.

如果更新表"attLeaveApplication",则触发器看起来不错.请仔细检查执行步骤,如果需要查看所有正在DB上执行的内容,也可以使用PROFILER.
Well, looking at the Trigger queries and AFAICU, do you need an Update trigger or an INSERT trigger?

Might be you want that, the moment Table "attLeaveApplication" get an application, you want to use this trigger. If so, you need to use INSERT trigger.

In case, of update of Table "attLeaveApplication", trigger looks fine. Please check the execution step wise, also use PROFILER if need to see what all are getting executed on DB.


这篇关于如何调试触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆