MySQL: Resetting auto-increment value of a table

During development, usually we want to delete records from the table manually, then the tables auto-increment column remains where it was. We might want to reset the auto-increment value for the table.

For example, if you delete records with id's 7,8,9
Now when you insert through application, it inserts the new record starting at 10. But we want it to start at 7.

Use the following SQL to reset to a specific value
 ALTER TABLE my_table AUTO_INCREMENT=7  

If you want to delete all records from your table and restart auto-index at 1, then
 TRUNCATE TABLE my_table 

1 comment:

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...