简体   繁体   English

SQL Server“更新后”触发更新前触发

[英]SQL Server “after update” trigger firing before update

I have an automated workflow which works on the basis of triggers. 我有一个基于触发器的自动工作流程。

There is an "AFTER UPDATE" Trigger on one of my table and it has a status field, once that field is updated from "Processing" to "Completed" the trigger must fire. 我的一张桌子上有一个“ AFTER UPDATE”触发器,并且它有一个状态字段,一旦该字段从“ Processing”更新为“ Completed”,触发器就必须触发。 And in normal case as per my understanding the trigger should fire after the status is updated to "Completed". 根据我的理解,在正常情况下,触发器应在状态更新为“已完成”后触发。

But in my case the trigger fires and results in potential deadlock or error and the status is still "Processing". 但是在我的情况下,触发器将触发并导致潜在的死锁或错误,并且状态仍为“处理中”。

AS per MSDN "AFTER" specifies that the trigger is fired only when all operations specified in the triggering SQL statement have executed successfully. 每个MSDN AS的“ AFTER”指定仅在触发SQL语句中指定的所有操作成功执行后才触发触发器。

Is there anything i can do to fire the triggers only once the update is committed to "Completed" status? 仅在将更新提交到“已完成”状态后,我有什么办法可以触发触发器?

Or does it mean that the "AFTER UPDATE" is just something which will begin as a transaction and then once trigger fires successfully the status is committed? 还是说“更新后”只是作为事务开始的,然后一旦触发器成功触发就提交状态?

Once the status is updated to "Completed" the "AFTER UPDATE" trigger fires, but the data is not yet committed. 将状态更新为“已完成”后,将触发“ AFTER UPDATE”触发,但尚未提交数据。 It would wait for the trigger to complete, in case of error in the trigger it would rollback the updated data. 它会等待触发器完成,如果触发器发生错误,它将回滚更新的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM