1

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?

1 Answer 1

4

You need to make use of the DELIMTIER trick 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:

DELIMITER $$
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 $$
DELIMITER ;
Sign up to request clarification or add additional context in comments.

Comments

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.