开发者

Raising errors in After Triggers Sql Server 2005

开发者 https://www.devze.com 2022-12-11 05:37 出处:网络
If I raise an error in an AFTER UPDATE trigger in Sql Server 2005, will that cause the update which caused the trigger to be fired to roll back, even if the statement was not executed within a transac

If I raise an error in an AFTER UPDATE trigger in Sql Server 2005, will that cause the update which caused the trigger to be fired to roll back, even if the statement was not executed within a transaction?开发者_如何学C

Thanks.


No, you have to rollback transaction by calling ROLLBACK TRAN:

CREATE TRIGGER trg_au_table
ON  dbo.table
AFTER UPDATE
AS 
BEGIN
    ROLLBACK TRAN
END
GO

This example will prevent from updating any record.

This:

CREATE TRIGGER trg_au_table
ON  dbo.table
AFTER UPDATE
AS 
BEGIN
    RAISERROR('This is a test', 16, 1)
END
GO

will only raise the error but the change will be made in the table.

0

精彩评论

暂无评论...
验证码 换一张
取 消