Mysql uses a trigger to synchronize two tables

Source: Internet
Author: User


Mysql uses triggers to synchronize two tables. Currently, the test is successful locally. Www.2cto.com assume that two local databases, a and B, and a have table table1 (id, val) and B have table table2 (id, val). Assume that you want to update data in table 1, synchronously update data in table 2. Code: DELIMITER $ CREATE/* [DEFINER = {user | CURRENT_USER}] */TRIGGER 'A '. 'trigger name' before update on 'A '. 'table1' for each row beginif new. id! = Old. id then update 'B '. 'table2' SET 'B '. 'table2 '. id = new. id WHERE 'B '. 'table2 '. val = old. val; end if; END $ DELIMITER, 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

Related Article

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.