Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up a trigger in mysql

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report