MYSQL触发器语法问题

时间:2013-11-12 11:42:57

标签: mysql triggers

我正在尝试此触发器,但它一直给我这个错误:

触发

DELIMITER $$
CREATE
TRIGGER entries_limit_trigger
BEFORE INSERT ON Feed
FOR EACH ROW
BEGIN
Set @counts=(SELECT count(*) from Feed);
IF (@counts > 10000)
THEN
PRINT 'INSERTED SUCCESS';
END IF; 
END
$$
DELIMITER ;

错误

#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 ''INSERTED SUCCESS'; END IF; END' at line 9

1 个答案:

答案 0 :(得分:0)

如果您希望触发器退出,您可以执行以下操作:

CREATE
TRIGGER entries_limit_trigger
BEFORE INSERT ON Feed
FOR EACH ROW
BEGIN
Set @counts=(SELECT count(*) from Feed);
IF @counts > 10000 THEN
  set @msg = "Reached the limit";
  SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @msg;
END IF; 
END;

sqlfiddle demo

要使其退出并显示消息,只需在小提琴中添加另一个插入内容。