I have two tables:
sanction
with these attributes:DriverID
,Calification
,Points
people
with these attributes:pID
,city
,TotalPoints
And i have this trigger:
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 ;
And when I try to execute this update
UPDATE sanctions
JOIN people ON sanctions.DriverID=people.pID
SET points=points+6
WHERE city='Barcelona' AND Calification='LightPenalty'
I get this error:
Can't update table 'people' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
How can i fix it? Thanks.
I use Windows 10 and MySQL server 5.7.17