Query to Re-index Primary Key of MySQL Database

- Posted in SQL by
ID | Value
1  | One
2  | Two
6  | Three
8  | Four
9  | Five

to

ID | Value
1  | One
2  | Two
3  | Three
4  | Four
5  | Five

sql query

SET @newid=0;
UPDATE tablename SET primary_key_id=(@newid:=@newid+1) ORDER BY primary_key_id;

s _https://stackoverflow.com/questions/10242311/query-to-re-index-primary-key-of-mysql-database

Tags: