本文介绍了从触发器回滚事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在 MS SQL Server 2008 R2 中,我们需要一个预插入和预更新触发器来检查某些内容并允许或回滚(通过 raiserror)正在运行的插入/更新.In MS SQL Server 2008 R2, we want a pre-insert and pre-update trigger which checks something and allows or rollbacks (via raiserror) the running insert/update.问题:在 INSTEAD OF 触发器中.真的必须明确地编写插入或更新吗?因为我们希望完成默认的插入或更新,并且只进行预检查".Question: In INSTEAD OF trigger. Does one really has to explicitly write the insert or update? Because we want the default insert or update to be done and only do the "precheck".推荐答案是.您确实需要编写显式的INSERT 或UPDATE.You do need to write the explicit INSERT or UPDATE.触发器运行INSTEAD OF DML 操作.如果您将触发器留空,则除了在 tempdb 中创建和填充的 INSERTED/DELETED 表之外不会发生任何操作.The trigger runs INSTEAD OF the DML operation. If you leave the trigger blank then no action will happen other than the INSERTED / DELETED tables being created and populated in tempdb.尽管从评论中的讨论来看,我根本不会为此使用触发器,而是使用唯一的过滤索引 CREATE UNIQUE INDEX ix ON T(a,b,c) WHERE c ''.在处理并发时,这可能会提高性能并避免潜在的逻辑问题.Although from discussion in the comments I would not use a trigger for this at all but use a unique filtered index CREATE UNIQUE INDEX ix ON T(a,b,c) WHERE c <> ''. This is likely to be more performant and avoid potential logic issues when dealing with concurrency. 这篇关于从触发器回滚事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!