My MySQL trigger doesn’t work, simple syntax, not complicated

A stored function or trigger cannot modify a table that is already
being used (for reading or writing) by the statement that invoked the
function or trigger.

from: Stored program restrictions.

Generally with a trigger that is fired on insert, if you want to change the value that is being inserted you make the trigger of the type BEFORE INSERT and change the values in NEW

also noticed that the following statement isn’t what you want anyway.

update pos_table set PTS=((NEW.won_games*2)+(NEW.tie_games*1));

It updates the entire table while I think you are only trying to update a sepcific row. Anyway, this is a simple calculation so you don’t really need to store this column. You can just as easily calculate the value at display time and make your code a whole lot simpler + avoid the issue with the trigger.

Leave a Comment