Mysql -- trigger operation, Mysql -- trigger operation
1. Why should I use a trigger?
2. Create a trigger 2.1 create a trigger with an execution statement
Example: There are two table objects in the database company: The Department table (t_dept) and the diary table (t_diary). When you create a trigger to insert a record to the Department table, the current time will be inserted into the diary table before insertion.
Department table:
Diary table:
Create a trigger:
Insert record:
Result: an additional record is added to the diary table.
2.2 create a trigger containing multiple execution statements
Syntax:
Example:
When a trigger is created to insert records into a department table, two records are inserted into the diary table.
Code Analysis:
Insert a record:
Result: There are two more records in the diary table:
3. view TRIGGER 3.1 view TRIGGER through show trigger statement
Syntax:
Example:
3.2 view the trigger by viewing the system table trigger
In Mysql, there is a system table triggers in the information_schema of the system database that stores all the trigger information. Therefore, you can query records in this table to view the trigger. The table structure is as follows:
View method:
View All triggers:
View the specified trigger:
4. delete a TRIGGER 4.1 delete a TRIGGER using the drop trigger statement
Syntax:
Example :"