MySQL Delete all rows from table and reset ID to zero

后端 未结 5 1999
野性不改
野性不改 2020-12-12 09:29

I need to delete all rows from a table but when I add a new row, I want the primary key ID, which has an auto increment, to start again from 0 respectively from 1.

5条回答
  •  暖寄归人
    2020-12-12 09:45

    Do not delete, use truncate:

    Truncate table XXX
    

    The table handler does not remember the last used AUTO_INCREMENT value, but starts counting from the beginning. This is true even for MyISAM and InnoDB, which normally do not reuse sequence values.

    Source.

提交回复
热议问题