mysql表中已有数据,为表新增一个自增id。

第一步,在navicat中,例如表test新建查询,输入以下两行代码即可搞定。

mysql表中已有数据,为表新增一个自增id。

alter table test add id int;
alter table `test` change id id int not null auto_increment primary key;

第二步,右键test表,设计,将id移动至第一行就可。

mysql表中已有数据,为表新增一个自增id。

 

mysql表中已有数据,为表新增一个自增id。

上一篇:mysql 实现类似Oracle 或 db2 sequence


下一篇:Django迁移数据库表报错AttributeError: 'str' object has no attribute 'decode'解决方案