How to reset autoincrement field in mySql

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to reset autoincrement field in mySql

Post by Saman » Fri Jan 26, 2018 9:50 am

1. Directly Reset Autoincrement Value

Alter table syntax provides a way to reset autoincrement column. Take a look at following example.

ALTER TABLE table_name AUTO_INCREMENT = 1;

Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

2. Truncate Table
Truncate table automatically reset the Autoincrement values to 0.

3. Drop & Recreate Table
This is another way of reseting autoincrement index.
Post Reply

Return to “PHP & MySQL”