Trigger (Trigger): The supervisor of a situation, and set out some kind of operation.
Trigger creation Syntax Four elements: 1, watch location (table) 2, monitor event (Insert/update/delete)
3, Trigger Time (After/before) 4, trigger event (Insert/update/delete)
Create Trigger Triggername
After/before (3) Insert/update/delete (2) on TableName (1)
For each row
Begin
SQL statements (4)
End
*1,2,3,4 corresponds to four elements
Let's start by creating two tables:
#test_datax
Create Table Test_datax (
user_id Int (12),
User_name varchar (225),
Latesttime Timestamp
);
#uptable
Create Table Uptable (
user_id Int (12),
User_name varchar (225),
Latesttime Timestamp
);
Delimiter $
Create Trigger TG1
After update on Test_datax
For each row
Begin
Insert into uptable (user_id,user_name,latesttime) values (old.user_id,new.user_name,new.latesttime);
end$
MySQL Flip-flop explanation