How to set up a trigger in mysql
This article is to share with you about how to build a trigger in mysql. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Create a trigger. The syntax for creating a trigger is as follows:
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW trigger_stmt
Where the name of the trigger_name identity trigger is specified by the user
Trigger_time identifies the trigger time and replaces it with before and after
Trigger_event identity trigger event, replaced with insert,update and delete
Tbl_name identifies the name of the table on which the trigger is created, that is, on which table the trigger is created
Trigger_stmt is the body of trigger programs; trigger programs can start and end with begin and end, with multiple statements in the middle
The existing sys_log_ log table, the sys_log_login_ record table, needs to query whether there is a record in the sys_log_login_record table that is consistent with the fd_operator_id in the sys_log_ log table when inserting a record in the sys_log_login_record table. If not, insert a new record in the sys_log_login_record.
Create Trigger loginRecord
After insert
On sys_log_login for each ROW
BEGIN
If not exists (select fd_operator_id from sys_log_login_record where fd_operator_id = NEW.fd_operator_id) then
Insert into sys_log_login_record values (NEW.fd_id,NEW.fd_operator_id,NEW.fd_create_time)
END IF
End
Delimiter
This is how to set up a trigger in mysql. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.