This question is an exact duplicate:

There is a trigger:

DELIMITER // create trigger betdesk_db.after_update_confirm after update on pre_Accounts for each row begin insert into Accounts(mail, `password`, solt, role_id) values (NEW.mail, NEW.password, NEW.solt, 2); delete from pre_Accounts where NEW.pre_account_id = pre_account_id; end; // DELIMITER ; 

The meaning is that when updating data in the pre_Accounts table, they are transferred to the Accounts table and deleted. However, an error occurs when updating data:

 update pre_Accounts set confirm = true where pre_account_id = 1; 

Data is not updated due to the following error:

Error Code: 1442. Can't update table

Where was I wrong, tell me ..

Reported as a duplicate by Anton Shchyrov , AK , Vadim Ovchinnikov , fori1ton , aleksandr barakin on Jan 27 '17 at 15:56 .

This question has been marked as a duplicate of an existing one.

  • Why it’s impossible to work with the right table right away? - Anton Shchyrov

1 answer 1

Your reason is given in the question "because it is already used by statement which invoked this stored function / trigger." In other words, you cannot delete a table from the same update trigger after update from the same table. Alternatively, you can try to delete the entry in the trigger for the Accounts table

  • Not take off. If a cascade of triggers is triggered, then no table that has spawned at least one trigger can be modified - Anton Shchyrov