Will MySQL reuse deleted ID's when Auto Increment is applied

前端 未结 5 1854
一生所求
一生所求 2020-12-09 09:04

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

That document I\'m reading seems to say something like:

\"In this case (when the AUTO_INCR

5条回答
  •  无人及你
    2020-12-09 09:50

    When you have a primary key field that is also auto_increment, no matter how many rows (or in what order) are removed, the ids that no longer exist are not used again, and the field is incremented continuously for each row.

    However, when your primary key consists of multiple fields (E.G. an auto_increment field and another field), the auto_increment field is reused, and only when the deleted id is the last id. What this means is if you have values like 1, 2, 3, 4, and 5, and you remove the row with the field value of 5, the next row will have an id of 5. However, if you remove the row with the id of 2, this will, again, not be used, and the next row will have an id of 6.

提交回复
热议问题