Iqbal Khan Iqbal Khan - 6 months ago 30
SQL Question

Phpmyadmin create trigger syntax error near 'END'

I'm trying to create a trigger in PhpMyAdmin, and I keep getting the same error everytime I try to create it. The error is:


#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 'END' at line 5


I can't seem to get it to work at all, all the questions I've seen about this topic all point to not setting the delimiter as the problem, but mine has already been set. Any help would be nice, I've created a very simple trigger just to test it out, the code is below:

DELIMITER ;
DROP TRIGGER IF EXISTS `triggerName`;
DELIMITER $$
CREATE TRIGGER `triggerName` AFTER UPDATE ON `test`
FOR EACH ROW
BEGIN
SELECT * FROM `test_2` WHERE `id` = 1
END $$
DELIMITER ;

Answer

Try ; after END and at the end of SELECT:

DELIMITER $$
CREATE TRIGGER `triggerName` AFTER UPDATE ON `test`
    FOR EACH ROW
        BEGIN
            SELECT * FROM `test_2` WHERE `id` = 1;
        END; $$
DELIMITER ;