mysql - 创建事件时出现错误#1064

标签 mysql

我有一张 table :

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

为什么会出现错误以及如何修复它?

最佳答案

在创建 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 */

关于mysql - 创建事件时出现错误#1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24463095/

相关文章:

javascript - 使用另存为对话框将 HTML 表格数据导出到 Excel (JQuery)

C# ASP.NET MySql 命令执行过程中遇到 fatal error

java - jcreator如何连接mysql?

MySQL 对多个 JOINS 使用 GROUP_CONCAT

mysql - SQL 按 2 个字段分组

php - 这个mysql查询有什么问题?

mysql - 获取用户的 SQL 查询

php - 将三个 mysql 条目合并为一个条目

mysql - SQL:按没有主键的表中的计数进行过滤

mysql - 我的sql搜索语法实现