1

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...!

1
  • @muistooshort [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON EACH ROW BEGIN DECLARE at vgls int; DECLARE at lgls int; SET at vgls' at line 2 Commented Oct 24, 2011 at 2:19

1 Answer 1

3

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.eqvis doesn'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 using ON EACH ROW when it should be FOR EACH ROW:

delimiter |
CREATE TRIGGER updpartido AFTER UPDATE ON partidos
FOR 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;
|
delimiter ;
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, my bad, i forgot about the delimiters! It worked like a charm! Thanks so much @muistooshort ! Have a nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.