myMySQL数据库如何将id重新排列 MySQL数据库使用教程

凤凰 2021-1-19 69 1/19

mysql将id重新排列的方法:1、使用column计数【alter table tablename drop column id】;2、使用increment排列【alter table tablenam auto_increment】。

myMySQL数据库如何将id重新排列 MySQL数据库使用教程

mysql将id重新排列的方法:

使用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

方法二不会清空已有数据,操作比较灵活,不仅可以将自增值归零,也适用于删除大量连续行后,重新设置自增值并插入新的数据;或从新的值开始,当然不能和已有的冲突。

$sql="delete from $table_vote"; 
mysql_query($sql, $link); 
$sql="alter table $table_vote auto_increment=1"; 
mysql_query($sql, $link);

更多相关免费学习推荐:mysql教程(视频)

以上就是mysql如何将id重新排列的详细内容,更多请关注本站其它相关文章!

- THE END -

凤凰

1月19日09:32

最后修改:2021年1月19日
0

非特殊说明,本博所有文章均为博主原创。