我正在尝试创建一个触发器,在将项目插入数据库时将它们标记为已删除。
可悲的是,我无法让我的 DECLARE 停止出错,我查看了 DECLARE 文档以及一些示例,但我一定遗漏了一些东西。
到目前为止我的查询是:
CREATE TRIGGER set_deleted BEFORE INSERT ON customercontact
FOR EACH ROW
BEGIN
DECLARE numrow INT; /* line 4 */
SELECT COUNT(*)
INTO numrow
FROM orders
WHERE NEW.order_id = 1;
if numrow >= 1 THEN
SET new.deleted = 1;
END IF;
END
错误消息显示:
#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 4
感谢您的帮助并阻止我为自己辩护!