更新后的MySQL触发器插入到具有条件的另一个表中

问题描述:

更新表之后的触发器的下面代码 student_approve 将数据插入表通知,但在第5行出现错误

Below code for my trigger after update table student_approve insert data to table notification but occurs error at line no 5

DROP TRIGGER IF EXISTS  `student_approve`;
CREATE TRIGGER `student_approve` AFTER UPDATE ON `student_info` 
FOR EACH ROW 
BEGIN
IF NEW.student_approval LIKE '1' THEN
INSERT INTO `notifications` (user_to_notify,who_fired_event,noti_event_id)VALUES(NEW.registered_by,1,2);
END IF;
END

LIKE不能用于简单比较,它仅在WHERE子句中受支持.不要忘记也要更改定界符.

LIKE cannot be used in a simple comparison it's only supported in a WHERE clause. Don't forget to change the delimiter as well.

DROP TRIGGER IF EXISTS  `student_approve`;
DELIMITER //
CREATE TRIGGER `student_approve` AFTER UPDATE ON `student_info` 
FOR EACH ROW 
BEGIN
   IF NEW.student_approval = '1' THEN
     INSERT INTO `notifications` (user_to_notify,who_fired_event,noti_event_id) VALUES(NEW.registered_by,1,2);
   END IF;
END//
DELIMITER ;

将解决语法错误,但是我当然不能确定结果是否是您想要的.

Would fix the syntax error but I of course we cannot tell if the result is what you want.