1

How can I reset the auto_increment of a field? I want it to start counting from 1 again after I delete all the data.

0

2 Answers 2

2
ALTER TABLE tablename AUTO_INCREMENT = 1;

See also the same question on stackoverflow.

1

It will be better to truncate table to start auto_increment from beginning of a auto_increment field:

Truncate table tableName;

as delete table starts auto_increment from last auto_incremented number.

Second option is, if you have to delete all data then you may drop and re-create table to start auto_increment from beginning.

4
  • thanks,.if my data 1,2,3 then i delete num 2 then it still 1,3 in the table. it should num 3 change into num 2. Can you help? Mar 22, 2018 at 6:50
  • It can't be changed as auto_incremented number checks last existing number. You have to do it manually. Mar 22, 2018 at 6:54
  • @SitiAisyah your question says "after I delete all the data" Mar 22, 2018 at 9:47
  • No, You may update manually update tableName Set columnName =2 where ColumnName =3 Mar 22, 2018 at 9:53

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