Why are the auto-increment mysql columns not arranged in order after some rows are deleted?

Source: Internet
Author: User
, Many rows are deleted between 15 and 44, but those between 45 and 46 are not placed between 15 and 44, while those between 46 and 50 are deleted by the following, fill back, why? And before 51? Then, there should be three vacancies between 46 and 50, but it is filled...

, Many rows are deleted between 15 and 44, but those 45 and 46 are not placed between 15 and 44,
The location between 46 and 50 was filled back by the 52,51 behind the deletion. Why? And before 51?
Then, there should be three vacant spaces between 46 and 50, but the space is filled with two spaces, and the 53 behind them goes to the 50 s. Why?

.................
According to your answers, it seems that I have not made it clear.
I did not ask why it was not 16 after 15, but why did go before 52 ??

Reply content:

, Many rows are deleted between 15 and 44, but those 45 and 46 are not placed between 15 and 44,
The location between 46 and 50 was filled back by the 52,51 behind the deletion. Why? And before 51?
Then, there should be three vacant spaces between 46 and 50, but the space is filled with two spaces, and the 53 behind them goes to the 50 s. Why?

.................
According to your answers, it seems that I have not made it clear.
I did not ask why it was not 16 after 15, but why did go before 52 ??

Auto-increment is not necessarily related to data deletion. The auto-increment ID has its own sequence, not the largest id + 1 in the table.

Auto-increment IDs are added according to the maximum value that has occurred, no matter whether you delete them or not.

MySQL stores such a maximum value for each auto-increment column, instead of finding the maximum value in the table each time.
Efficiency problems, think about it ......

In addition, serial numbers are meaningful and can be referred to the basic principles of database design.
Each sequence number corresponds to a specified thing.
This design can also avoid confusion due to incomplete deletion (such as ID-related columns in another table but not deletion.

Last ......
I have many years of experience and will not delete anything that can be deleted.
Integrity, recoverability, data mining ......
Adding a column as a tag (indicating whether it is valid) is better than the deletion design.

PS: It seems that you have not understood the problem ......
The sorting problem depends on your SQL. If you care about the order, writeOrder.

Order
Otherwise, mysql only displays data according to its rules. If you do not specify a rule, do not expect it to comply with the rules you want.

Is data inserted sorted?

1. Auto-increment id refers to auto-increment when writing a table, instead of deleting a row like excel, which is automatically moved up downstream.

2. The sequence is incorrect. Why didn't you execute sort? Or by another field sort?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.