Auto Increment after delete in MySQL

后端 未结 17 2132
醉酒成梦
醉酒成梦 2020-11-22 09:50

I have a MySQL table with a primary key field that has AUTO_INCREMENT on. After reading other posts on here I\'ve noticed people with the same problem and with varied answer

17条回答
  •  日久生厌
    2020-11-22 10:40

    I came here looking for an answer to the Title question "MySQL - Auto Increment after delete" but I could only find an answer for that in the questions

    • How to delete certain row from mysql table?
    • How to reset AUTO_INCREMENT in MySQL?

    By using something like:

    DELETE FROM table;
    ALTER TABLE table AUTO_INCREMENT = 1;
    

    Note that Darin Dimitrov's answer explain really well AUTO_INCREMENT and it's usage. Take a look there before doing something you might regret.

    PS: The question itself is more "Why you need to recycle key values?" and Dolph's answer cover that.

提交回复
热议问题