About the auto-increment ID, each time a piece of data is deleted, and then 1, 2, 3, 4 cannot be connected... For example, if you delete the third data record, it will become 124.
Reply to discussion (solution)
Ignore him
A primary key (generally id) is a unique identifier that does not have other meanings.
The IDs of the auto-incrementing primary keys in Mysql database tables are messy and need to be rearranged. You can do this
Principle: delete the original auto-increment ID and create a new auto-increment ID.
1. delete the original primary key:
Alter table 'Table _ name' DROP 'id ';
2. add the new primary key field:
Alter table 'Table _ name' add'id' MEDIUMINT (8) not null first;
3. set the new primary key:
Alter table 'Table _ name' modify column 'id' MEDIUMINT (8) not null AUTO_INCREMENT, add primary key (id)
This is the case.
InnoDB records the maximum ID of the auto-increment primary key in the memory. Therefore, if your current id is 4, the auto-increment record is 4. even if you delete data, the maximum value is still this.
However, if you restart mysql, you will find that if it is inserted, it is connected in order, that is, what you said.
A table ID auto-incrementing primary key. after four records are inserted, 2, 3, and 4 records are deleted, Mysql is restarted, and another record is inserted, is the ID of this record 2 or 5?
Also, you can look at this:
Http://flandycheng.blog.51cto.com/855176/280224
This phenomenon is normal.
In fact, I just want to get the first 10 pieces of data. how can this problem be solved ??? How to write without auto-increment
Select... limit 10
The primary key is only a unique identifier. you don't have to worry about the break number. if you want to query 10 items, add limit 10 at the end of your query statement, you cannot use id <10 as the query condition, so the number of queried results will only be <= 10
It turned out to be something as good as limit. Potholes