更新后的MySQL触发器插入到具有条件的另一个表中 [英] Mysql trigger after update insert into another table with condition
本文介绍了更新后的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.
这篇关于更新后的MySQL触发器插入到具有条件的另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文