Re-Indexing MySQL INT Primary Keys & Reset AUTO_INCREMENT

后端 未结 2 781
再見小時候
再見小時候 2021-01-14 18:26

So I have a MySQL database that I\'m using with a PHP site. Over the course of weeks of development, I\'m left with something like:

Table: users

id  | name         


        
相关标签:
2条回答
  • 2021-01-14 18:39

    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.

    0 讨论(0)
  • 2021-01-14 18:53

    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

    0 讨论(0)
提交回复
热议问题