How to reorder MySQL auto increment primary key

1083645 pts.
Tags:
Database
MySQL
I'm using MySQL and in my table, I have an auto increment primary keys. I already deleted several rows in the middle of the table. Now, I need to reorder the keys but I'm not sure how to do it. Can someone help me?

Answer Wiki

Thanks. We'll let you know when a new response is added.
SET @count = 0;
UPDATE `table_name` SET `table_name`.`id` = @count:= @count + 1;
ALTER TABLE table_name AUTO_INCREMENT = 1;

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: