An example of a simple MySQL trigger

Source: Internet
Author: User
Tags mysql trigger example

A simple MySQL trigger example requires that a field in a table be updated. If the new value is smaller than the old value in the table, the old value and the new value are added, and then update; otherwise, the system will be updated normally. Consider using the MySQL trigger to trigger the update. The following is a specific SQL statement. [SQL] -- delete TRIGGER DROP TRIGGER trigger_ads; -- CREATE TRIGGER DELIMITER // CREATE TRIGGER trigger_ads BEFORE UPDATE ON stats_ads FOR EACH ROW BEGIN IF OLD. VIEW> NEW. view then set new. VIEW = OLD. VIEW + NEW. VIEW; end if; if old. view_unique> NEW. view_unique then set new. view_unique = OLD. view_unique + NEW. view_unique; end if; if old. click> NEW. click then set new. click = OLD. click + NEW. click; end if; if old. click_unique> NEW. click_unique then set new. click_unique = OLD. click_unique + NEW. click_unique; end if; if old. START> NEW. start then set new. START = OLD. START + NEW. START; end if; if old. start_unique> NEW. start_unique then set new. start_unique = OLD. start_unique + NEW. start_unique; end if; if old. landing> NEW. landing then set new. landing = OLD. landing + NEW. landing; end if; if old. landing_unique> NEW. landing_unique then set new. landing_unique = OLD. landing_unique + NEW. landing_unique; end if; END; // you can use the following SQL statement to view all triggers: [SQL] -- View mysql trigger SELECT * FROM information_schema. 'trigger ';

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.