MySQL查询语法错误。尝试在简单查询上创建每日事件但语法错误

时间:2016-09-02 17:02:47

标签: mysql

我正在尝试创建一个永远在00 HRS每天执行的活动。我无法弄清楚我做了什么语法错误。 我的代码:

delimiter |

CREATE EVENT IF NOT EXISTS schedule_updation
ON SCHEDULE EVERY 1 DAY
STARTS CURRENT_DATE()
DO
  ALTER TABLE `bookings` DROP COLUMN `Date1`;
  ALTER TABLE `bookings` CHANGE `Date2` `Date1` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
  ALTER TABLE `bookings` CHANGE `Date3` `Date2` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
  ALTER TABLE `bookings` CHANGE `Date4` `Date3` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
  ALTER TABLE `bookings` CHANGE `Date5` `Date4` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
  ALTER TABLE `bookings` CHANGE `Date6` `Date5` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL;
  ALTER TABLE `bookings` ADD `Date6` TEXT after `Date5`;

  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 'ALTER TABLE `bookings` CHANGE `Date2` `Date1` TEXT CHARACTER SET latin1 COLLATE ' at line 6

数据库版本:

  • 服务器:本地数据库(通过TCP / IP 127.0.0.1)
  • 服务器类型:MySQL
  • 服务器版本:5.7.11 - MySQL社区服务器(GPL)
  • 协议版本:10

2 个答案:

答案 0 :(得分:0)

事件DO只能有一个"语句"作为它的身体。如果您需要多个语句,则需要BEGIN / END块;

CREATE...
DO single_statement;

CREATE ...
DO BEGIN
    statement1;
    statement2;
    ...
END

答案 1 :(得分:0)

虽然列未声明为NOT NULL UNIQUE,但应该没有问题。 尝试

ALTER TABLE `bookings` CHANGE `Date2` `Date1` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL;

ALTER TABLE `bookings` CHANGE `Date2` `Date1` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci null default null;