MySQL Trigger notes

Source: Internet
Author: User

Typically used to detect inserted values when inserting a table, or to calculate a value on update.

The app can be manipulated when insert,update,delete a table

Grammar:

Creating a trigger CREATE TRIGGER trigger name Before/after insert/update/delete on table name for each row SQL statement

Such as:

Create trigger Cal_num before insert on Test.account for each row set @[email Protected]+new.amount;

If you have more than one SQL statement, you need to wrap the SQL statement with begin...end such as:

Mysql>delimiter//
Mysql>CREATE TRIGGER Upd_check before UPDATE on account
-For each ROW
-BEGIN
-IF New.amount < 0 Then
-SET new.amount = 0;
- ELSEIF New.amount > THEN< /strong>
SET New.amount = +;
END IF;
end;//
delimiter;

Each column has a old,new old, which means "delete/update", and new means [insert/update].




This article is from the "Linux Learning path" blog, so be sure to keep this source http://raystudylinux.blog.51cto.com/9065684/1767798

MySQL Trigger notes

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.