MySQL - auto decrementing value

后端 未结 5 1703
孤城傲影
孤城傲影 2021-01-06 04:47

Let\'s say that I\'ve got a table, like that (id is auto-increment):

id | col1 | col2
1  | \'msg\'| \'msg\'
2  | \'lol\'| \'lol2\'
3  | \'xxx\'| \'x\'
         


        
5条回答
  •  别那么骄傲
    2021-01-06 05:20

    You can renumber the whole table like this:

    SET @r := 0;
    UPDATE  mytable
    SET     id = (@r := @r + 1)
    ORDER BY
            id;
    

提交回复
热议问题