在已有的mysql表中添加自增字段

现有数据表xiami,建表的时候忘记添加自增字段,现需要添加自增字段

第一步:添加字段

alter table xiami add id int;

第二步:修改字段

alter tabel xiami change id id auto_increment not null primary key;

问题:

表中记录数量为3929966

Query OK, 3929966 rows affected (2 min 8.09 sec)
Records: 3929966  Duplicates: 0  Warnings: 0  

查看创建表命令时,auto_increment为3932618

>> show create table xiami;

...

ENGINE=InnoDB AUTO_INCREMENT=3932618 DEFAULT CHARSET=utf8

为什么auto_increment与记录数不一致?

猜你喜欢

转载自www.cnblogs.com/chimpan/p/9625719.html