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!