Stop MySQL Reusing AUTO_INCREMENT IDs

后端 未结 5 1646
闹比i
闹比i 2020-12-07 01:40

I have a table with an AUTO_INCREMENT primary key. If the last row in the table is deleted, the next-inserted row will take the same ID.

Is there a way of getting My

5条回答
  •  -上瘾入骨i
    2020-12-07 01:52

    As I understand it, there is no way of doing this. You might consider working around it by adding a deleted flag, and then setting the deleted flag instead of removing the row.

    The "right" answer is that once a row is deleted, you shouldn't be referencing it. You can add foreign keys to make sure that the db will not allow rows to be deleted that are referenced elsewhere in the db.

提交回复
热议问题