Re: deleted primary key can't be reused? [message #181902 is a reply to message #181827] |
Fri, 21 June 2013 17:25 |
GravyCode
Messages: 2 Registered: June 2013
Karma:
|
Junior Member |
|
|
On Saturday, June 8, 2013 10:24:27 PM UTC+8, richard wrote:
> Entered 100 items into 2 columns each.
>
> Deleted 2.
>
> Upon entering new record using id of 98, no can do.
>
> The next new record number becomes 101.
>
> "Duplicate key error" is issued.
>
> How do I take back the deleted key number so I can use it again?
>
> No, I do not mean the data that is in the record.
>
> To me, once a record is deleted, the key index should reflect that the
>
> record no longer exists, so the key index should be -1 of what it was.
>
> Not continue its esistance.
Just reset the auto increment to 1 and it should jump to the next available empty number, if your first untaken id is 98, then the next insert will take that position.
ALTER TABLE `table_name` AUTO_INCREMENT =1;
|
|
|