简体   繁体   English

在触发器Sql Server 2005中引发错误

[英]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? 如果我在Sql Server 2005中的AFTER UPDATE触发器中引发错误,那么是否会导致导致触发器的更新被回滚,即使该语句未在事务中执行?

Thanks. 谢谢。

No, you have to rollback transaction by calling ROLLBACK TRAN : 不,你必须通过调用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. 只会引发错误,但会在表格中进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM