Search code examples
mysqlauto-incrementreset

SQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field


I want a query which can set an auto increment value in mysql database to 0.

In my case i want a column called "id" to be reset to 0.


Solution

  • ALTER TABLE some_table AUTO_INCREMENT=0
    

    If you want to delete all records from your table and restart auto-index at 0, you might be tempted to run a DELETE query, followed by the above example, setting the auto increment value to 0. There is a shortcut, however:

    TRUNCATE TABLE some_table