开发者

Have mysql re-allocate ids in a continuous range

开发者 https://www.devze.com 2022-12-21 18:43 出处:网络
I have an existing database in mysql. One of my tables has discontinuous ids. I would like to modify the ids of the table so that they go from 1 to num-of-rows.

I have an existing database in mysql. One of my tables has discontinuous ids. I would like to modify the ids of the table so that they go from 1 to num-of-rows.

This particular tables does not happen to have incoming references, so the ids can be changed without modifying other tables.

The reason I want to do that is th开发者_如何学JAVAat I want to process the data with a tool I am writing and if the ids are continuous then many things will be simpler.


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

精彩评论

暂无评论...
验证码 换一张
取 消