Logging into table in SQL Server trigger

前端 未结 4 419
猫巷女王i
猫巷女王i 2021-01-13 14:30

I am coding SQL Server 2005 trigger. I want to make some logging during trigger execution, using INSERT statement into my log table. When there occurs error during execution

4条回答
  •  迷失自我
    2021-01-13 15:23

    Don't know if I'm thinking too simple, but why not just change the order of the error handler to insert AFTER the rollback??

    if (@err = 1)
    begin
        RAISERROR (@msg, 16, 1)
        rollback transaction
        INSERT INTO dbo.log(date, entry) SELECT getdate(), 'ERROR: ' + out from #output
        return
    end
    

提交回复
热议问题