MySQL triggers currently do not support direct declaration of parameters. A trigger is a database object associated with a table. It can define a series of operations on a specific table in response to operations on the data in the table. For insert, update, or delete operations, although MySQL triggers do not have explicit parameter declarations, parameters can be passed by setting custom variables on the table to which the trigger belongs.
Operating system for this tutorial: Windows 10 system, MySQL 8 version, Dell G3 computer.
In MySQL, a trigger (Trigger) is a database object associated with a table. It can define a series of operations on a specific table in response to the insertion of data in the table. , update or delete operations. MySQL triggers currently do not support direct declaration of parameters.
The definition syntax of a trigger is as follows:
CREATE TRIGGER trigger_name {BEFORE | AFTER} {INSERT | UPDATE | DELETE} ON table_name FOR EACH ROW trigger_body
In trigger_body, you can reference rows that are newly inserted or updated using the NEW keyword, and deleted or updated rows using the OLD keyword. OK. Through these keywords, row data related to the operation can be accessed in the trigger.
Although MySQL triggers do not have explicit parameter declarations, parameters can be passed by setting custom variables on the table to which the trigger belongs. In this way, these variables can be used in the definition of the trigger to complete specific logical operations.
For example, you can define custom variables on the table and use them in triggers:
SET @my_param = 'some_value'; CREATE TRIGGER my_trigger AFTER INSERT ON my_table FOR EACH ROW BEGIN -- 使用 @my_param 来进行逻辑操作 -- ... END;
MySQL triggers do not have the ability to directly declare parameters, but by using the table level Custom variables can achieve similar functions to achieve the effect of passing parameters in triggers.
The above is the detailed content of Can mysql triggers have parameters?. For more information, please follow other related articles on the PHP Chinese website!