mysql表示列位置并同时添加注释

时间:2016-08-12 03:38:57

标签: php mysql

当我在MySQL中添加一个新列时,我写了这个:

alter TABLE table_name add column `column2` int NOT null DEFAULT 0 after `column1` COMMENT 'this is comment'

似乎无法添加评论并从ALTER TABLE Syntax同时说明该列的位置。有没有办法只在一个SQL中完成它们?

2 个答案:

答案 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`