Re-Indexing MySQL INT Primary Keys & Reset AUTO_INCREMENT

不打扰是莪最后的温柔 提交于 2019-12-01 09:18:27

remove index on id

do something like this:

SET @rank:=0;
update users
set id=@rank:=@rank+1
order by id;

add index on id

Why do you need to change the order of the names in the database? You can just add an ORDER BY name clause on your sql query to get the results in alphabetical order by name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!