Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to reset AUTO_INCREMENT of field in MySQL?

How to reset the AUTO_INCREMENT of a field?
I want it to begin counting from 1 again.
by

2 Answers

RoliMishra
ALTER TABLE tablename AUTO_INCREMENT = 1;
Shahlar1vxp
You can reset the AUTO_INCREMENT of a field in MySQL using the code-
ALTER TABLE tablename AUTO_INCREMENT = value
There is one more way to reset the AUTO_INCREMENT with PHPMyAdmin under the tab name 'operations' and then you can easily set the autoincrement to the value you want, in the 'table' option.
And it is to be noted that you are not allowed to reset the counter to any value less than or equal to any value that has been already used.
There is a short example:
ALTER TABLE my_table MODIFY COLUMN ID INT (10) UNSIGNED;
COMMIT;
ALTER TABLE my_table MODIFY COLUMN ID INT (10) UNSIGNED AUTO_INCREMENT;
COMMIT;

With this, the auto-increment counter gets reset and will start automatically from the maximum value that exists.

Login / Signup to Answer the Question.