Wednesday, October 07, 2009

Reset your MySQL Table Auto Increment Value

Recently,I created tables using auto increment number as the Primary Key. As name say, the number will increase every time I insert new record into the table. At some point I wanted to delete the whole dummy data I inserted.

ALTER TABLE tablename AUTO_INCREMENT = value;


eg.
If I had a items table and I created a few new items and then deleted them, to set the auto increment value back to ‘100′ i would simply:

ALTER TABLE items AUTO_INCREMENT = 100;

3 comments:

సుబ్రహ్మణ్యేశ్వర రెడ్డి said...

Can you tell me how to reset the auto increment of all the tables in a database at a time

Anonymous said...

nice post, but no need to get the maximum values , it will set automatically you can get it from here

http://webobserve.blogspot.com/2011/02/reset-mysql-table-autoincrement.html

guru said...

Thanks

SHOW ENGINE INNODB STATUS

  The SHOW ENGINE INNODB STATUS command in MySQL provides detailed information about the internal state of the InnoDB storage engine. This ...