Auto Increment skipping numbers?

后端 未结 4 620
旧巷少年郎
旧巷少年郎 2020-12-03 14:21

Note: I\'m new to databases and PHP

I have an order column that is set to auto increment and unique.

In my P

4条回答
  •  被撕碎了的回忆
    2020-12-03 15:15

    auto increment doesn't care, if you delete some rows - everytime you insert a row, the value is incremented.

    If you want a numbering without gaps, don't use auto increment and do it by yourself. You could use something like this to achive this for inserting

    INSERT INTO tablename SET
        `order` = (SELECT max(`order`) + 1 FROM (SELECT * from tablename) t),
        ...
    

    and if you delete a row, you have to rearange the order column manually

提交回复
热议问题