有的时候需要对于一个Mysql数据库表添加个自动增长主键,刚开始的时候使用下面的语句:
alter table taskinfoconfig add column id int(10) not null auto_increment ;
alter table taskinfoconfig add primary key(id);
可是在执行的时候发现报错,信息如下:
Incorrect table definition; there are only one auto column and it must be defined as a key.
错误说明只有主键才能被指定为自动增长列,而上面的第一条语句在执行时id还不是主键,因此报错。
后来从网上找了找,其实可以使用一条语句解决:
alter table add taskinfoconfig add column id int(10) not null auto_increment primary key;