SQL Server:在触发器中暂停INSERT [英] SQL Server: halt an INSERT in a trigger

查看:271
本文介绍了SQL Server:在触发器中暂停INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发器 FOR INSERT ,我需要通过引发错误来停止插入。

I have a trigger FOR INSERT and I need to stop the insertion by raising a error.


RAISERROR

RAISERROR

将显示错误消息,但是有一种方法可以使其他任何方法不执行交易停止操作?

will show the error message but is there is a way to halt the action any other method without transactions ?

推荐答案

您需要一个 INSTEAD OF 触发器(无双关)来控制它。 FOR INSERT (触发插入)触发器在插入后发生,因此这匹马早已被拴住了。

You need an INSTEAD OF trigger instead (no pun intended) to control it. A FOR INSERT trigger occurs AFTER the insert, so the horse has long bolted.

这篇关于SQL Server:在触发器中暂停INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆