Mysql trigger newold details bitsCN.com
Mysql trigger new old
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;
BitsCN.com