Wednesday, February 13, 2013

Reorder/Reset auto increment primary key?


Following query can be used for reorder auto increment of a table.In this example reorder the id column of users table. If there are foreign key, make sure the action is cascade.

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

0 comments:

Post a Comment