mysql数据库自增id重新从1排序的两种方法
使用mysql时,通常表中会有一个自增的id字段,但当我们想将表中的数据清空重新添加数据时,希望id重新从1开始计数,用以下两种方法均可:
通常的设置自增字段的方法:
创建表格时添加:
create table table1(id int auto_increment primary key,...)
创建表格后添加:
alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key.
例子
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
您可能感兴趣的文章:
Mysql 主键自增长auto_increment问题分析
MySQL常见错误代码解析
设计高效合理的MySQL查询语句的建议
javascript排序算法代码解析
MariaDB与MySQL数据库之间有什么区别
HTML5中indexedDB 数据库的相关介绍
mysql中修改密码及权限控制的方法参考
ubuntu下mysql配置
indexedDB 数据库
高性能mysql学习笔记总结