Forum Moderators: open
I created a script that will look at my table daily to delete records past the expiration date.
Let's say I have five records, ids: 1, 2, 3, 4, 5.
If records 1, 2, and 4 or deleted, I've noticed that if three new records are added, it will be placed in slots 6, 7, and 8. However, I would like to "recycle" lower unused numbers 1, 2, and 4.
How can I do this?
ALTER TABLE `table_name` AUTO_INCREMENT = new_value;
where new_value is the value you want to assign to the counter.
It is not possible to use a new auto_increment value lower than currently exists in the table. In your example table with ID 1,2,3,4,5 where 1,2 and 4 are deleted, the remaining values will be 3 and 5. The lowest AUTO_INCREMENT value you can set in that case is 6.