谁能告诉我创建触发器语法有什么问题?

时间:2010-06-12 22:05:44

标签: mysql triggers

我第一次尝试使用触发器。

当我尝试使用以下内容创建触发器时:

CREATE TRIGGER t_foldersPrivate BEFORE DELETE ON foldersPrivate
FOR EACH ROW BEGIN
 DELETE FROM programs WHERE folderType = '0' AND folderID = OLD.ID; 
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 3`

(mysql 5.1.37)

如果我删除了delete语句,则create trigger语句可以正常工作。所以我认为它必须与此有关。但对于我的生活,我不确定是什么......

1 个答案:

答案 0 :(得分:1)

您应该更改分隔符。

这样的事情:

DELIMITER $$

CREATE TRIGGER t_foldersPrivate BEFORE DELETE ON foldersPrivate
FOR EACH ROW BEGIN
 DELETE FROM programs WHERE folderType = '0' AND folderID = OLD.ID; 
END$$

DELIMITER ;

此外,您应该单独检查删除查询。它有效吗?