How to reorder a primary key?

前端 未结 5 1010
小蘑菇
小蘑菇 2021-01-01 06:21

I have a table of 5700 records. The primary key is an integer. Now I noticed that some values are missing. Like this:

100 data
101 data 
102 data
104 data
         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 06:54

    Try this:

    SET @var:=0;
    UPDATE `table` SET `id`=(@var:=@var+1);
    ALTER TABLE `table` AUTO_INCREMENT=1; 
    

提交回复
热议问题