Reputation: 43
I created a table department
with 4 columns and set deparmentid
column to autoincrement. Now, after deleting 8 records out of 10, on adding the new record the value of departmentid
is shown as 11 instead of 3. I truncated the whole table but again it is showing the same result on inserting the data. What should I do?
Upvotes: 0
Views: 1165
Reputation: 710
You can reset the counter with:
ALTER TABLE tablename AUTO_INCREMENT = 1
For InnoDB you cannot set the auto_increment value lower or equal to the highest current index.
Upvotes: 2
Reputation: 1834
This is how auto increment is working. It doesn't matter if you delete from the table. If you want to change the auto increment id you need to run
ALTER TABLE department AUTO_INCREMENT = 3;
Upvotes: 0