MySQL Delete all rows from table and reset ID to zero

marek_lani picture marek_lani · Sep 29, 2012 · Viewed 272.2k times · Source

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.

Answer

Francois picture Francois · Sep 29, 2012

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.