Generally, if we use the ID auto-incrementing primary key and delete the key, we cannot simply rank the ID again. Here are some operation tips.
The IDS of the auto-incrementing primary keys in Mysql database tables are messy and need to be rearranged.
Principle: Delete the original auto-increment ID and create a new auto-increment ID.
1. Delete the original primary key:
The Code is as follows: |
Copy code |
Alter table 'table _ name' DROP 'id '; |
2. Add the new primary key field:
The Code is as follows: |
Copy code |
Alter table 'table _ name' add'id' MEDIUMINT (8) not null first; |
3. Set the new primary key:
The Code is as follows: |
Copy code |
Alter table 'table _ name' modify column 'id' MEDIUMINT (8) not null AUTO_INCREMENT, add primary key (id ); |
Another way is to use php to re-create a data record. When deleting data, you only need to add the delete mark. If you do not delete the data record, you can.