Resetting MySQL Auto Increment Field

After developing a number of systems in the past it is of course essential to completely test any piece of software. This of course means that any tables that use an auto_increment field will not start from 1 when the system goes live. Not a massive problem but it is nice sometimes to reset the value to 1.

After searching around the web what seemed like an age I finally found the SQL that carry s out just the job.

Enter the following statement into your MySQL database replacing tablename with the name of your table and the value x to the number you want the AUTO_INCREMENT value to start from:

ALTER TABLE tablename AUTO_INCREMENT = x

There you go the AUTO_INCREMENT field in this case will now be reset to 1

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *