Mysql trigger insert MySQL trigger important learning materials:
Http://dev.mysql.com/doc/refman/5.1/zh/triggers.html
When using a trigger, an error occurs:
[SQL]insert into tb_recharge_records(user_id,pointcoupon_added) values(214983,10);[Err] 1442 - Can't update table 'tb_recharge_records' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Search for information:
Http://blog.csdn.net/liuliu20036/article/details/4158891
This new record is updated when the trigger is inserted. error it is already used by statement which invoked this stored functiontrigger solution
Problem:
Create trigger InsertUser
Begin
Update users
Set user_power = '[resource]'
Where user_id = new. user_id;
End;
When the trigger is executed, an error occurs: Mysql5.0 is used.
Can't update table 'users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
What is going on here?
Solution:
If you insert/update the inserted data in the trigger, this problem occurs. This will cause loop calls.
You should use the set operation instead of using update in the trigger, for example
Create trigger InsertUser
Begin
Set new. user_power = '[resource]'
End;
In addition, the trigger must be executed before insertion.
================
The insert time is automatically added when a record is added using a trigger.
Set @ newid = NEW. recharge_id;
If @ newid> 0 then
Update tb_recharge_records set add_time = now () where recharge_id = @ newid and "" = "trigger cannot call host table ";
End if;