0

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?

4
  • 1
    You need a semicolon at the end of the SIGNAL statement. Commented Oct 30, 2017 at 16:27
  • I did that too and it says unexpected token ; near Commented Oct 30, 2017 at 16:29
  • You really have a table named "employess"? Commented Oct 30, 2017 at 16:30
  • Yes I have a table named employess Commented Oct 30, 2017 at 16:48

1 Answer 1

4

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

3 Comments

Thanks for the comment.That does not work either. It still gives me unexpected token ; near . Pic: tinypic.com/r/oab1fs/9
@bhuvanesharasu . . . Are you using a rather archaic version of MySQL?
I am using phpmyadmin. But when I used MySQL workbench this worked. I then figured out that there is something wrong with the phpmyadmin version. Thank you! It worked :)

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.