mysql对自增id重新从1排序的两种方法

使用mysql时,通常表中会有一个自增的id字段,但当我们想将表中的数据清空重新添加数据时,希望id重新从1开始计数,用以下两种方法均可:

方法一:

alter table tablename drop column id;
alter table tablename add id mediumint(8) not null primary key auto_increment first;

方法二:

alter table tablename auto_increment=0

发布了172 篇原创文章 · 获赞 3 · 访问量 25万+

猜你喜欢

转载自blog.csdn.net/sizheng0320/article/details/5125918