MySQL觸發器更新本表資料異常:Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this
如果你在觸發器裡面對剛剛插入的資料進行了 insert/update, 則出現這個問題。因為會造成迴圈的呼叫.
create trigger test
before update on test
for each row
update test set NEW.updateTime = NOW() where id=NEW.ID;
END
應該使用set操作,而不是在觸發器裡使用 update,比如
create trigger test
before update on test
for each row
set NEW.updateTime = NOW();
END