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

前端 未结 5 1826
一生所求
一生所求 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:32

    As described with the InnoDB engine the last PK utilised will be reused if the row is deleted prior to a reboot as it is not cached. If this PK is a Foreign Key (FK) in another table problems can arise (FK hell). This is how I discovered the problem when a little old lady shot up to 195 cm(!) as the deleted person's additional data was picked up. The work around for this is either to implement 'ON DELETE CASCADE' for the child tables or (not my preferred option) to code around this issue.

提交回复
热议问题