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.

ypercubeᵀᴹ
  • 99,450
  • 13
  • 217
  • 306
Siti Aisyah
  • 11
  • 1
  • 2

2 Answers2

2
ALTER TABLE tablename AUTO_INCREMENT = 1;

See also the same question on stackoverflow.

dbdemon
  • 6,964
  • 4
  • 21
  • 40
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.

Pankaj Kumar
  • 409
  • 2
  • 5
  • 14