我有兩個表:MySQL錯誤1442
sanction
with these attributes:DriverID
,Calification
,Points
people
with these attributes:pID
,city
,TotalPoints
,我有這個觸發器:
DROP TRIGGER IF EXISTS updatePoints_tgr;
delimiter $$
CREATE TRIGGER
updatePoints_tgr AFTER UPDATE
ON sanctions FOR EACH ROW
BEGIN
if NEW.points > OLD.points
THEN
UPDATE people
SET TotalPoints = TotalPoints + (NEW.points - OLD.points)
WHERE people.pID = NEW.DriverID;
elseif NEW.points < OLD.points
THEN
UPDATE people
SET TotalPoints = TotalPoints - (NEW.points - OLD.points)
WHERE people.pID = NEW.DriverID;
END IF;
END$$
delimiter ;
,當我嘗試執行此更新
UPDATE sanctions
JOIN people ON sanctions.DriverID=people.pID
SET points=points+6
WHERE city='Barcelona' AND Calification='LightPenalty'
我得到這個錯誤:
Can't update table 'people' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
我該如何解決它?謝謝。
我使用的是Windows 10和MySQL服務器5.7.17
我不是這方面的專家,但我不認爲你可以......對公平而言,對於'後期更新'有點令人驚訝。 –
Windows 10 6.3.8版本構建1228 CE(64位) –
我們可以試着證明(使用bug跟蹤器)它不是特定於該版本的bug(或者它可能是!),而是預期的行爲。稍後我會回到這個問題,看看我能找到什麼,如果沒有人打我的話,因爲它很有趣。 –