Create a trigger for mysql _ MySQL

Source: Internet
Author: User
Create a trigger for mysql bitsCN.com. The trigger creation syntax is as follows:

Create trigger trigger_name trigger_time trigger_event
ON tbl_name for each row trigger_stmt

Trigger_name indicates the trigger name, which you can specify;

Trigger_time indicates the Trigger Time, which must be replaced by before and after;

Trigger_event identifies the trigger event and replaces it with insert, update, and delete;

Tbl_name identifies the table name on which the trigger is created;

Trigger_stmt is the trigger program Body. the trigger program can use begin and end as the start and end, with multiple statements in the middle;


The existing sys_log_login table and two-dimensional table need to query whether the sys_login_record table has the same records as the fd_operator_id in the sys_log_login table when inserting a record in the sys_log_login table;




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;
BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.