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