开发者

Can anyone tell me what is wrong with my create trigger syntax?

I am experimenting with triggers for the first time.

When I try to create a trigger using the following:

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

I receive the following error:

`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)

If 开发者_StackOverflowI get rid fo the delete statement the create trigger statement works fine. So I am assuming it must have something to do with that. But for the life of me I'm not sure what...


You should change the delimiters.

Something like this:

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 ;

Also, you should check the delete query separately. Is it working?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜