我想修改一个像这样的表:
ALTER TABLE book
ADD COLUMN `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `id`,
CHANGE COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT,
CHANGE COLUMN `author_id` bigint unsigned NOT NULL;
但它一直提示语法错误:
#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 'bigint unsigned NOT NULL AUTO_INCREMENT, CHANGE COLUMN `author_id` bigint un' at line 3
我不知道我在这里做错了什么。对我来说,SQL似乎很好,并且每个表的修改都可以成功执行:
ALTER TABLE book ADD COLUMN `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `id`;
ALTER TABLE book CHANGE COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT;
ALTER TABLE book CHANGE COLUMN `author_id` bigint unsigned NOT NULL;
我可以使用单独的版本,但是有一些很大的表需要修改,因此最好使用一个结合查询,应该会更快。
为什么组合的SQL不起作用?
ALTER TABLE sub_subject ADD
tstimestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER
id, MODIFY
idbigint unsigned NOT NULL AUTO_INCREMENT, CHANGE
subjectbigint unsigned NOT NULL;
- datasn.io