mysql delete,autoincrement

后端 未结 4 1569
攒了一身酷
攒了一身酷 2020-12-11 07:25

I have a table in MySQL using InnoDB and a column is there with the name \"id\".

So my problem is that whenever I delete the last row from the table and then insert

4条回答
  •  轮回少年
    2020-12-11 08:09

    You have two major misunderstandings about how a relational database works:

    1. there is no such thing as the "last row" in a relational database.
    2. The ID (assuming that is your primary key) has no meaning whatsoever. It doesn't matter if the new row is assigned the 33, 35354 or 236532652632. It's just a value to uniquely identify that row.

    Do not rely on consecutive values in your primary key column.

    And do not try the max(id)+1 approach. It will simply not work in a system with more than one transaction.

提交回复
热议问题