我正在尝试创建一个永远在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
数据库版本:
答案 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;