所以我已經編輯我的代碼 我在另一個觸發這個問題,但這個時間甚至可更改WHERE子句不利於MySQL的觸發器不能更新表:已經通過調用該觸發器的語句使用
DELIMITER $$
CREATE TRIGGER pic_album_change AFTER UPDATE ON pictures
FOR EACH ROW BEGIN
UPDATE albums SET counter = counter + 1 WHERE albums.id = NEW.album_id;
UPDATE albums SET counter = counter - 1 WHERE albums.id = OLD.album_id;
END $$
DELIMITER ;
錯誤:
<p>Error Number: 1442</p><p>Can't update table 'pictures' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
我沒有看到在這個觸發器中的照片表進行任何修改
我還有一個觸發器,它涉及到這兩個表
DELIMITER $$
CREATE TRIGGER album_change
AFTER UPDATE
ON albums
FOR EACH ROW
BEGIN
UPDATE pictures
SET
level = NEW.level
WHERE
pictures.album_id = NEW.id ;
END $$
DELIMITER ;
http://stackoverflow.com/questions/9227382/cant-update-table-that-trigger-is-executed-on-in-after-insert – Samson 2012-07-08 09:32:15
我認爲你的WHERE子句是錯誤的方法回合。 'WHERE albums.id = NEW.album.id'會導致'albums.counter'增加(大概是每張專輯中的圖片數量)。 – 2012-07-08 09:33:37
@radashk感謝您的鏈接,但正如我所說我的觸發器沒有附在同一張桌子上 – max 2012-07-08 09:39:03