im trying to make an trigger that updates a table when i modify another table…
Here is my code:
CREATE TRIGGER updpartido AFTER UPDATE ON partidos
ON EACH ROW
BEGIN
SET @vgls = SELECT vgoles(NEW.eqvis)
SET @lgls = SELECT vgoles(NEW.eqloc)
UPDATE equipos SET gf=@vgls WHERE id=NEW.eqvis
UPDATE equipos SET gf=@lgls WHERE id=NEW.eqloc
END
What it must do is, when i update an match, it must automaticly run this trigger and update the goals.
But it gives me an error.
What im doing wrong? Thanks and have a nice day…!
I notice that you don’t have any statement terminators in your trigger, that will generate some complaints because, for example,
SET @lgls = SELECT vgoles(NEW.eqloc) UPDATE equipos SET gf=@vgls WHERE id=NEW.eqvisdoesn’t make any sense. So you need some semicolons in the trigger but you also need to get those semicolons past the parser by temporarily changing the delimiter. You’re also usingON EACH ROWwhen it should beFOR EACH ROW: