1. Test data table: mysql> select * from T1;
+ ------ + ------- +
| ID | Name |
+ ------ + ------- +
| 1 | name1 |
+ ------ + ------- +
1 row in SET (0.00 Sec)
mysql> select * From T2;
+ ------ + ------- +
| ID | Name |
+ ------ + ------- +
| 1 | name1 |
+ ------ + ------- +
1 row in SET (0.00 Sec) 2. create a trigger in the command line: mysql> delimiter //
mysql> Create trigger test. t1_ai after insert on test. t1
-> for each row begin
-> Update T2 Set ID = 3;
-> end //
query OK, 0 rows affected (0.11 Sec) This trigger inserts new records in Table T1 into Table t2 3. Insert a new record to table T1 in the command line: mysql> insert into T1 values (2, 'name2');
query OK, 1 row affected (0.05 Sec) 4. View the record information in the data table again: mysql> select * from T1;
+ ------ + ------- +
| ID | Name |
+ ------ + ------- +
| 1 | name1 |
| 2 | name2 |
+ ------ + ------- +
2 rows in SET (0.00 Sec)
mysql> select * From T2;
+ ------ + ------- +
| ID | Name | Container Freight
+ ------ + ------- +
| 1 | name1 |
| 2 | name2 |
+ ------ + ------- +
2 rows in SET (0.00 Sec) TP-link tutorial visible, our trigger has taken effect! 5. command Line deletion trigger: mysql> drop trigger t1.t1 _ AI;