Address: http://database.51cto.com/art/201010/229404.htm
Next we will introduce you to the MySQL trigger new old for your reference. If you have encountered similar problems in MySQL trigger, you may wish to take a look and I believe it will help you.
MySQL trigger new old:
"New. column_name" or "old. column_name". Technically, new | old. column_name and old
The column name belongs to the created transition variable ("transition variables ").
For insert statements, only new statements are valid. For Delete statements, only old statements are valid. For update statements
Old is used at the same time. The following is an example of using both new and old in update.
- CREATE TRIGGER tr1
- BEFORE UPDATE ON t22
- FOR EACH ROW
- BEGIN
- SET @old = OLD.s1;
- SET @new = NEW.s1;
- END;
If the value of column S1 in Table T21 is 55, the value of @ old is 55 after "Update T21 set S1 = S1 + 1" is executed,
The value of @ new will change to 56.
Trigger execution interval: The for each row clause notifies the trigger to execute an action on every row instead of the entire table.
Increasing column values:
- Create Table (
- Id int primary key auto_increment, # Set to auto Increment
- Name varchar (10)
- );
Set the initial value to 1000:
Alter table tablename auto_increment = 1000;