Suppose I have a script with the code for a trigger, how do I actually start up the script so that the trigger is active? How do I stop it?
-
1More information please. Code example perhaps?bozdoz– bozdoz2012-11-25 02:33:09 +00:00Commented Nov 25, 2012 at 2:33
-
It is just a simple trigger saved in a .sql file. I do not know how to run(execute) this file.Trup– Trup2012-11-25 02:48:22 +00:00Commented Nov 25, 2012 at 2:48
-
@Trup Does the below answer help?Alex W– Alex W2012-11-25 02:53:32 +00:00Commented Nov 25, 2012 at 2:53
1 Answer
If you have a script that has code for creating a MySQL trigger, you would simply execute the script in order to create the trigger assuming the script contains MySQL statements along the lines of:
CREATE
[DEFINER = { user | CURRENT_USER }]
TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_body
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
To get rid of a trigger that you have created, you use the DROP statement in MySQL accompanied by the name of the trigger, or create another script to execute the SQL statement:
DROP TRIGGER [IF EXISTS] [schema_name.]trigger_name
http://dev.mysql.com/doc/refman/5.6/en/drop-trigger.html
To execute a SQL file you would simply type @[file_name].sql at the SQL prompt in the command line: