• 方法一:

原来的id取消自增和主键,只用于表格的排序。

新插入一个id2,自然会根据自增重新排列。删除id,id2改id即可。

alter table 你的表名字 drop 你的表的主键;
alter table 你的表的名字 add 你的表的主键 int not null primary key auto_increment first;
alter table table_name drop id;
alter table table_name add id int not null primary key auto_increment first;

使用这种方法不影响表中数据,从1递增开始递增

  • 方法二:清空表,并重置id
truncate table table_name;

一次性删除所有数据,不可恢复,无法回滚

  • 方法三:
delete from table_name;
alter table table_name auto_increment= 1;
  • 方法四:
ALTER TABLE table_name AUTO_INCREMENT = 1;
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐