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?
Asked
Active
Viewed 1,140 times
0

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Andy
- 43
- 9
-
Possible duplicate of [How to reset AUTO\_INCREMENT in MySQL?](http://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql) – Giacomo Garabello Jun 07 '16 at 06:37
2 Answers
2
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.

aarju mishra
- 710
- 3
- 10
0
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;

Vasil Rashkov
- 1,818
- 15
- 27