如何重置MySQL数据库表中的id
新插入一个id2,自然会根据自增重新排列。删除id,id2改id即可。原来的id取消自增和主键,只用于表格的排序。使用这种方法不影响表中数据,从1递增开始递增。一次性删除所有数据,不可恢复,无法回滚。
·
- 方法一:
原来的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;
更多推荐
已为社区贡献1条内容
所有评论(0)