Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

triggers

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

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 Statement field for fooTrigger so the trigger does something different? Or do I need to drop and re-create the trigger?

like image 629
Cory Klein Avatar asked Jul 17 '12 15:07

Cory Klein


People also ask

How do I edit an existing trigger in MySQL?

To modify an existing trigger, double-click the node of the trigger to modify, or right-click this node and choose the Alter Trigger command from the context menu. Either of the commands opens the SQL Editor.

How do I update a trigger in MySQL workbench?

Answer: In MySQL, there's no statement to update or alter an existing trigger. If after trigger creation, you need to change the trigger. You can DROP the existing trigger using the DROP TRIGGER command and create a new one with the same name.

How do I DELETE an existing trigger in MySQL?

To destroy the trigger, use a DROP TRIGGER statement. You must specify the schema name if the trigger is not in the default schema: mysql> DROP TRIGGER test.


1 Answers

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

Documentation: CREATE TRIGGER DROP TRIGGER

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

SELECT * FROM INFORMATION_SCHEMA.TRIGGERS

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

Documentation: INFORMATION_SCHEMA.TRIGGERS

like image 95
Jocelyn Avatar answered Nov 13 '22 08:11

Jocelyn