开发者

Raising errors in After Triggers Sql Server 2005

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜