MySQL An after delete Trigger + Update on same table

时间:2016-04-21 22:38:16

标签: mysql sql database

I want to update a table which is also tied on a "after delete" trigger.

DELIMITER §
CREATE TRIGGER sorting
AFTER DELETE ON tb_number
FOR EACH ROW
BEGIN
UPDATE tb_number SET number1 = number1 - 1 WHERE number1 >= old.number1;
END § 
DELIMITER ;
DELETE FROM tb_number where number1 = 2;

Why does not work this? It says:

 Error Code: 1442. Can't update table 'tb_number' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

So how can I fix this with trigger? I thought, after-delete means: Once a deletion has been executed, the trigger will update...

0 个答案:

没有答案