Search code examples
mysqlsqlmysql-error-1064

MySQL Error on Before Trigger for END IF Statement


Hello I am trying to write a trigger in mysql and below is my code`

DELIMITER $$
CREATE TRIGGER updateNewEmp
BEFORE INSERT ON employess
FOR EACH ROW
BEGIN
    IF new.salary <50000 THEN
    SIGNAL SQLSTATE '45000'
    END IF
END$$
DELIMITER ;

But I get an error stating #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'END IF END' at line 7. Could someone please explain what am I doing wrong here?


Solution

  • Try putting semicolons in:

    DELIMITER $$
    CREATE TRIGGER updateNewEmp
    BEFORE INSERT ON employess
    FOR EACH ROW
    BEGIN
        IF new.salary <50000 THEN
            SIGNAL SQLSTATE '45000';
        END IF;
    END$$
    
    DELIMITER ;