Is there a way to reset the auto incrementing value of a field so it starts back at 1 ?

+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment | 
| name  | varchar(45)      | NO   |     | NULL    |                | 
+-------+------------------+------+-----+---------+----------------+
link|improve this question

feedback

2 Answers

up vote 7 down vote accepted

To reset back to it's lowest possible value.

ALTER TABLE <tablename> AUTO_INCREMENT=0;

If you're doing it because you've deleted records with the view to resetting a table back to an empty state, then consider using TRUNCATE in the future, which will take care of the auto increment for you.

TRUNCATE <tablename>;
link|improve this answer
feedback

ALTER TABLE tbl_name AUTO_INCREMENT = 1

If the table is empty.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.