so I have the following query:
CREATE TRIGGER `before_delete`
BEFORE DELETE ON `abc` FOR EACH ROW
BEGIN
DELETE FROM def WHERE OLD.id = objID1 OR OLD.id = objID2;
DELETE FROM ghi WHERE OLD.id = objID;
END;
but then mysql complains that there’s syntax error near ‘END’ at line 1….
what did I do wrong?
You need to make use of the
DELIMTIERtrick to include multiple statements in a procedure block. Otherwise it can’t tell the difference between the end of your procedure and the end of statements inside it. On the documentation page, there is an example using the delimiter keyword.To save you the trouble of going to that page and looking around, I think this will fix it: