如何在 SQL Server 2005 中创建禁用的触发器?
使用 Oracle 时,您可以创建禁用的触发器,并在触发器主体之前指定单词 DISABLE。如何在Sql Server中达到同样的效果?
When using Oracle you can create a disabled trigger specifing the word DISABLE before the trigger body. How can I achive the same effect in Sql Server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您确实必须创建禁用的触发器,则在事务中创建并禁用它:
GO 在那里,因为 CREATE TRIGGER 必须是批处理中的第一个语句,但根据您部署代码的方式,您可能可以使其看起来更整洁一些。
If you really must create the trigger disabled then create and disable it within a transaction:
The GOs are there because CREATE TRIGGER must be the first statement in a batch, but depending on how you deploy your code you can probably make it look a bit neater.
我这样做的方法是执行创建和禁用,如下所示:
这允许我在同一脚本中创建和禁用,而无需任何 GO。
The way I did it was to EXEC both the create and the disable like:
This allowed me to create and disable in the same script without the any GO's.
如果您更喜欢不需要事务的解决方案,但也消除了触发器触发并在创建触发器和禁用触发器之间执行操作的机会,那么您可以基本上不使用任何代码来创建触发器在其中,然后禁用它,然后更改它以包含其实际主体:
If you prefer a solution that doesn't require a transaction, but that also eliminates the chance of the trigger firing and doing its thing between the moment it is created and the moment it is disabled, then you can create the trigger with basically no code in it, then disable it, and then alter it to include its actual body:
第一次创建空触发器(不执行任何操作),
第二次禁用它,
第三步将其修改为所需的内容,
第四,需要时启用它
1st create empty trigger (performing no action),
2nd disable it,
3rd alter it with the desired content,
4th enable it when needed
T-SQL 提供了 DISABLE TRIGGER 语句来完成相同的事情。您可以在此处找到详细信息:禁用触发语法
T-SQL provides a DISABLE TRIGGER statement that accomplishes the same thing. You can find the details here: DISABLE TRIGGER SYNTAX
在管理工作室中,展开表下的触发器文件夹,然后右键单击触发器并禁用。
MSDN:禁用触发器 (Transact-SQL)
MSDN:启用触发器 (Transact-SQL)
sql-server-disable-all -数据库上的触发器禁用所有服务器上的所有触发器
In management studio Expand Trigger folder under table and Right Click on Trigger and Disable.
MSDN:DISABLE TRIGGER (Transact-SQL)
MSDN:ENABLE TRIGGER (Transact-SQL)
sql-server-disable-all-triggers-on-a-database-disable-all-triggers-on-all-servers