不太写触发器,今天遇到个语法问题,在朋友(DBA)的帮助下解决了,记录下来。
需求:在CLASS_PROPERTY_REL删除记录时,调用存储过程gen_ci_property_value
问题反馈:
SQL 错误 [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 'DELIMITER
CREATE TRIGGER cpr_del AFTER DELETE ON CLASS_PROPERTY_REL FOR EACH ROW' at line 1
解决方案:
DELIMITER $$
CREATE TRIGGER cpr_del AFTER DELETE ON CLASS_PROPERTY_REL FOR EACH ROW
BEGIN
CALL gen_ci_property_value();
END$$
DELIMITER ;
解释:
因为创建proc的语句是个整体,你不希望执行一行就结束了,所以需要临时改变一下定界符,结束后,‘DELIMITER ;’是把定界符再改回默认