使用CREATE EVENT时出错#1064

时间:2014-06-28 02:44:26

标签: mysql

我有一张桌子:

CREATE TABLE test_time (`id` int(11) not null, `num` int(11) not null, PRIMARYKEY(`id`);

之后,我创建了一个事件:

CREATE
EVENT testEvent
ON
SCHEDULE EVERY 1 SECOND 
DO 
BEGIN
UPDATE
    test_time
SET
    num = num + 1 
WHERE 
    id = 1;

UPDATE
    test_time
SET
    num = num + 1 
WHERE 
    id = 2;
END

和MySQL说:(注意:第12行是id = 1;)

#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 12

为什么是错误,我该如何解决?

1 个答案:

答案 0 :(得分:0)

您需要在创建CREATE事件之前更改分隔符,并在第一个分号处停止。完成后,您需要将其更改回来。

CREATE TABLE if not exists test_time 
   (`id` int(11) not null, `num` int(11) not null, PRIMARY KEY(`id`));

drop event if exists testEvent;

Delimiter $$                 /* New delimiter set here */
CREATE EVENT testEvent
  ON SCHEDULE EVERY 1 SECOND 
DO 
  BEGIN
    UPDATE test_time SET num = num + 1 WHERE  id = 1;  /* old delimiter not actioned */
    UPDATE test_time SET num = num + 1 WHERE  id = 2;
  END $$                                               /* New delimiter to end CREATE */

delimiter ;            /* Reset delimiter */