当我在MySQL中添加一个新列时,我写了这个:
alter TABLE table_name add column `column2` int NOT null DEFAULT 0 after `column1` COMMENT 'this is comment'
似乎无法添加评论并从ALTER TABLE Syntax同时说明该列的位置。有没有办法只在一个SQL中完成它们?
答案 0 :(得分:2)
这对我有用
ALTER TABLE `table_name` ADD `column_name` INT NOT NULL DEFAULT '0' COMMENT 'some comments' AFTER `some_column`;
确保some_column
已存在
答案 1 :(得分:2)
使用以下查询同时添加和评论
ALTER TABLE `table_name` ADD COLUMN `column2` int NOT NULL DEFAULT 0 COMMENT 'this is comment' AFTER `some_column`