简体   繁体   中英

how can I rearrange the ID orders?

My table has 500 rows of users, but their ids are something like these now: "7454,21201, 31317..."

I would like to rearrange the ID orders to "1,2,3,4,5....".

What can I do? thanks

It is a column named id in users table

Try this query. Hope it's help to find your solution

SET @count = 0;
UPDATE `users` SET `users`.`id` = @count:= @count + 1;
ALTER TABLE users AUTO_INCREMENT = 1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM