MySQL triggers are an important part of the MySQL database. The following describes how to create and delete MySQL triggers in detail.
MySQL triggers are an important part of the MySQL database. The following describes how to create and delete MySQL triggers in detail.
MySQL triggers are an important part of the MySQL database. The following describes how to create and delete MySQL triggers in detail.
1. Create a Mysql trigger:
Syntax:
Create trigger trigger_name trigger_time trigger_event ON tbl_name
FOR EACH ROW
BEGIN
Trigger_stmt
END;
Create trigger trigger_name trigger_time trigger_event ON tbl_name for each row begin trigger_stmt END; uppercase keywords
Trigger_name: Mysql trigger name. My frequently used naming rules are t_name_tableName _ (B | a) (I | u | d), t: trigger ID, name: English name, tableName: table Name,
B (BEFORE): BEFORE the event is triggered,
A (AFTER): AFTER an event is triggered,
I (insert): identifies an insert event,
U (update): identifies an update event,
D (delete): identifies a delete event;
Trigger_time: trigger time (BEFORE or AFTER)
Trigger_event: event name (insert, update, or delete)
Tbl_name: Table Name (must be a permanent table)
Trigger_stmt: Execute the statement (which can be a compound language name). Use the OLD and NEW aliases to reference columns in the table related to the trigger program.
2. Delete the Mysql producer
Syntax:
Drop trigger [schema_name.] trigger_name;
Note: The above operations require the SUPER permission.
Create and delete MySQL triggers
The following article describes how to create a MySQL trigger and how to delete a MySQL trigger. If you create a MySQL trigger correctly, if you are interested in deleting the MySQL trigger, you can click the following article to view it.
1. Create a MySQL trigger:
Syntax:
Create trigger trigger_name trigger_time trigger_event ON tbl_name
FOR EACH ROW
BEGIN
Trigger_stmt
END;
Create trigger trigger_name trigger_time trigger_event ON tbl_name
FOR EACH ROW
BEGIN
Trigger_stmt
END;
Example
Create trigger SetUserHome after insert ON users
FOR EACH ROW
BEGIN
Update 'users' set homeLocationX = 128,
HomeLocationY = 128, homeLocationZ = 30
Where uuid = NEW. uuid
END
The preceding example is incorrect. Updating the table when it is triggered will bring the program into an endless loop.
For more details, please continue to read the highlights on the next page:
Related reading:
High-performance data creation using MySQL triggers
Use of MySQL triggers
MySQL trigger Management
MySQL trigger to process data in this table
MySQL trigger settings in Linux