您可以在创建后修改现有的 mysql 触发器吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11525930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:11:51  来源:igfitidea点击:

Can you modify an existing mysql trigger after it has been created?

mysqltriggers

提问by Cory Klein

In mysqlI can create a trigger, and then show information about it like this:

mysql我可以创建一个触发器,然后像这样显示有关它的信息:

mysql> show triggers like 'fooTrigger';

This command gives output that looks an awful lot like a select statement, with a row showing the matching trigger. Is it possible to update a column on the row it shows me?

这个命令给出的输出看起来很像一个选择语句,一行显示匹配的触发器。是否可以更新它显示给我的行上的列?

For example, one column is named Statement, and it defines what happens when the trigger is activated. Is it possible to change the Statementfield for fooTriggerso the trigger does something different? Or do I need to dropand re-createthe trigger?

例如,一列名为Statement,它定义了激活触发器时会发生什么。是否可以更改Statement字段fooTrigger以便触发器执行不同的操作?还是我需要drop重新create触发?

回答by Jocelyn

As of MySQL 5.5, you must drop and re-create the trigger.
It is not possible to update the Statementcolumn without dropping the trigger.

从 MySQL 5.5 开始,您必须删除并重新创建触发器。
Statement不删除触发器的情况下更新列是不可能的。

Documentation: CREATE TRIGGERDROP TRIGGER

文档:CREATE TRIGGER DROP TRIGGER

You may also access information about triggers using the INFORMATION_SCHEMA tables:

您还可以使用 INFORMATION_SCHEMA 表访问有关触发器的信息:

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS

But, as these tables are actually views, you can't use UPDATEon them.
It's just a more convenient way to access and manipulate the information than using SHOW TRIGGERS.

但是,由于这些表实际上是视图,因此您不能UPDATE对它们使用。
与使用 SHOW TRIGGERS 相比,这只是一种更方便的访问和操作信息的方式。

Documentation: INFORMATION_SCHEMA.TRIGGERS

文档:INFORMATION_SCHEMA.TRIGGERS

回答by Ravinder Reddy

You may require, on Windows OS, Connector/Net Visual Studio Integrationto view and edit existing database object. Limitation is that you can only edit triggerbody within For each row ...loop.

在 Windows 操作系统上,您可能需要连接器/Net Visual Studio 集成来查看和编辑现有数据库对象。限制是您只能在循环内编辑触发器主体For each row ...

Otherwise only option one has is drop and re create the trigger.
But make sure before dropping a trigger that the table associated with a trigger is locked and
and unlocked after trigger is re-created.

否则,只有一个选项是删除并重新创建触发器。
但请确保在删除触发器之前,与触发器关联的表已锁定,
并在重新创建触发器后解锁。