Created
January 20, 2016 09:00
-
-
Save anasabbasi/a1a03e76e546fda7bf62 to your computer and use it in GitHub Desktop.
Reindex a MySQL table's primary key field. Helpful, if rows have been deleted from the middle and you have an OCD, like me.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @newid=0; | |
UPDATE tablename SET primary_key_id=(@newid:=@newid+1) ORDER BY primary_key_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment