SQL Server XACT_ABORT with exclusion

后端 未结 3 1306
南旧
南旧 2021-01-21 16:55

I have a larger stored procedure which utilizes several TRY/CATCH blocks in order to catch and log individual errors. I have also wrapped a transaction around the entire content

3条回答
  •  心在旅途
    2021-01-21 17:20

    I don't know details but IMHO general logic can be like this.

    --set XACT_ABORT ON --not include it
    declare @result varchar(max) --collect details in case you need it
    begin transaction
    begin try
    --your logic here
    --if something wrong RAISERROR(...@result)
    --everything OK
    commit
    end try
    begin catch
    --collect error_message() and other into @result
    rollback
    end catch
    insert log(result) values (@result)
    

提交回复
热议问题