Question

I am trying to create new trigger like this. But it gives me an error.

DELIMITER $$
CREATE TRIGGER email_postid_truncate BEFORE INSERT
ON email_postid
BEGIN

SET @cnt = (SELECT count(*) FROM email_postid WHERE status='Remaining');
IF @cnt = 0 THEN

    --My query

END IF;
END $$

DELIMITER ;

This trigger gives error like this

enter image description here Please help.

Was it helpful?

Solution

You have missed FOR EACH ROW statement

CREATE TRIGGER email_postid_truncate BEFORE INSERT
ON email_postid
FOR EACH ROW
BEGIN
....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top