Update field on field change trigger I'm trying to create a trigger that sets an updated flag when a field is changed. The reason I can't do it with a basic UPDATE query is because the change will come from a INSERT ON DUPLICATE UPDATE.

This is the trigger:

CREATE TRIGGER set_update_flag BEFORE UPDATE ON `reputation_email_score`
FOR EACH ROW
    BEGIN
        IF NEW.`score` &lt;&gt; OLD.`score` THEN
          SET NEW.`updated` = "yes";
        END IF;
    END;


When I try to run it, I get these errors:

Error in query (1064): Syntax error near '' at line 5
Error in query (1064): Syntax error near 'END IF' at line 1
Error in query (1064): Syntax error near 'END' at line 1


What is wrong in my SQL query?
You forget about DELIMITER:

DELIMITER $$

CREATE TRIGGER set_update_flag BEFORE UPDATE ON `reputation_email_score`
FOR EACH ROW
    BEGIN
        IF NEW.`score` &lt;&gt; OLD.`score` THEN
          SET NEW.`updated` = "yes";
        END IF;
END $$
DELIMITER ;


also ; after last END - not necessary