Spent about one hour to understand.
Where is this sql trigger contain syntax error?
CREATE
TRIGGER playlis_trubric_count_on_playlist_shared_update
AFTER UPDATE ON playlist_playlist
FOR EACH ROW
IF (NEW.shared != OLD.shared) AND (NEW.shared = 1) THEN
UPDATE etv.playlist_playlistrubric
SET count = playlist_playlistrubric.count + 1
WHERE etv.playlist_playlistrubric.id = NEW.rubric_id;
ELSEIF (NEW.shared != OLD.shared) AND (NEW.shared = 0) THEN
UPDATE etv.playlist_playlistrubric
SET count = playlist_playlistrubric.count - 1
WHERE etv.playlist_playlistrubric.id = NEW.rubric_id
END IF;
ERROR SAYS:
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 ‘ELSEIF (NEW.shared != OLD.shared) AND (NEW.shared = 0) THEN
UPDATE etv.p’ at line 1
From the documentation:
You’re missing
BEGINandENDand you’re also going to need the delimiter trick, because at present your trigger definition ends at the firstNEW.rubric_id(which is why the parse error occurs just after that point).