Mysql uses triggers to synchronize two tables: bitsCN.com
Mysql uses a trigger to synchronize two tables
Currently, the local test is successful.
Assume that two local databases a and B have table1 (id, val) and table2 (id, val) in Table)
Assume that you want to synchronize data updates in table 1 and Table 2.
Code:
DELIMITER $
CREATE
/* [DEFINER = {user | CURRENT_USER}] */
TRIGGER 'A'. 'trigger name' BEFORE UPDATE
ON 'A'. 'table1'
FOR EACH ROW BEGIN
IF new. id! = Old. id THEN
UPDATE 'B'. 'table2' SET 'B'. 'table2'. id = new. id WHERE 'B'. 'table2'. val = old. val;
End if;
END $
DELIMITER;
I found a lot of code on the Internet, and it failed to run in phpadmin. it was always a syntax error and phpmyadmin could not create a trigger visually. so I found another mysql management tool, SQLyog. This tool is good. for java writing, you can create a trigger on the interface, and then copy the code to phpmyadmin to run it successfully!
SQLyog:
Http://www.webyog.com/en/downloads.php#sqlyog
BitsCN.com