TSQL: Try-Catch Transaction in Trigger

后端 未结 9 1701
长发绾君心
长发绾君心 2020-12-05 08:09

I am trying to put a try-catch statement inside a trigger using Microsoft Server 2005.

BEGIN TRANSACTION
BEGIN TRY
    --Some More SQL
    COMMIT TRANSACTION         


        
9条回答
  •  日久生厌
    2020-12-05 08:27

    It might be helpful to know what your are trying to do in the trigger.

    The trigger is part of the transaction that sent the data to the inserted or deleted tables. If it fails, it will rollback the whole transaction. If you are expecting the trigger to fail occasionally but not rollback the statement that casued the trigger to fire, then perhaps you need to rethink whether a trigger is the right thing to use.

提交回复
热议问题