简体   繁体   中英

Rectify my syntax error in mysql triggers

So im trying create a mysql trigger (before update) that would check which attribute of the employee table is getting updated and I will be adding a statement to another table 'Update_Message' which indicates the attribute that gets updated. This is my code:

DELIMITER //

CREATE TRIGGER update_col
BEFORE UPDATE
ON Employee FOR EACH ROW
BEGIN
    DECLARE Msg VARCHAR(100);
    SET Msg = '';
    IF NEW.eid!=OLD.eid THEN 
       SET Msg = CONCAT(Msg,"trying to update eid");
    ELSE IF STRCMP(NEW.ename,OLD.ename) = 0 THEN
       SET Msg = CONCAT(Msg,"trying to update ename");
    ELSE IF STRCMP(NEW.eaddress,OLD.eaddress) = 0 THEN
       SET Msg = CONCAT(Msg,"trying to update eaddress");
    ELSE
       SET Msg = CONCAT(Msg,"trying to update emonthlysalary");
    DELETE FROM Update_Message;
    INSERT INTO Update_Message (Message) VALUES (Msg);
END;
// 

It points out a syntax error: ERROR 1064 (42000): 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 '' at line 17

Please Help

Read https://dev.mysql.com/doc/refman/8.0/en/if.html

 IF search_condition THEN statement_list [ELSEIF search_condition THEN statement_list]... [ELSE statement_list] END IF

You're missing the END IF that must complete this statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM