1

I am creating a trigger on update operation. However, while creating trigger in MySQL5 it is giving an error.

Trigger:

CREATE TRIGGER `test`.`Employee_Trigger_Update`
     AFTER UPDATE ON `test`.`employee`
     FOR EACH ROW
     BEGIN
     INSERT into `test`.`Employee_log`
     (id,description)
     VALUES 
     (old.id, CONCAT('Id with '
                       , old.id
                       ,' is modified from '
                       , OLD.start_date
                       , ' to '
                       , NEW.start_date)    );

Error

Error Code : 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 '' at line 8 (0 ms taken)

If some one could please help it would be greatly appreciated

1

2 Answers 2

2

You need to use a different delimiter other than semicolon

DELIMITER $$

CREATE TRIGGER `test`.`Employee_Trigger_Update`
     AFTER UPDATE ON `test`.`employee`
     FOR EACH ROW
     BEGIN
     INSERT into `test`.`Employee_log`
     (id,description)
     VALUES 
     (old.id, CONCAT('Id with ',old.id,' is modified from ',OLD.start_date, ' to ', NEW.start_date));
END $$

DELIMITER ;
Sign up to request clarification or add additional context in comments.

1 Comment

now i am getting error- Error Code : 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 $$ DELIMITER' at line 1 (0 ms taken)
1

one thing i see , you dont have - END; in the end of trigger declare , see examples and documentation here

1 Comment

i have used "END ;" at the end of query but now it is giving error -Error Code : 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 1 (0 ms taken)

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.