Tuesday, February 28, 2012

[MySQL] Reset Auto Increment

Sometimes when we create a program that was paired with a database, we test it like hundred or thousand times before we say that it was working correctly. As a result of this the id, which was always auto incremented will now be starting in like more or less 100 so often we just delete the table and create it again for the id to start again on zero. There is a way to reset the auto increment counter by altering the table itself. Here's the code:

This will start the counter at zero
ALTER TABLE tbl_name AUTO_INCREMENT = 0

This will start the counter at 10
ALTER TABLE tbl_name AUTO_INCREMENT = 10

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...