Possible Duplicate:
MySQL: Reorder/Reset auto increment primary key?
if I delete from my table a ligne and in this table i have an auto increment ID , DELETE From table where id=2
after this the table will be like this
ID | NAme
1 aaa
3 cccc
how can i fix the ID to be like this
ID | NAme
1 aaa
2 cccc
3 dddd
Reset the auto increment fieldALTER TABLE `table` AUTO_INCREMENT = number; Replacing 'number' with the result of the previous command plus one and replacing table with the table name. If you deleted all the rows in the table, then you could run the alter table command and reset it to 0.
You use TRANCATE table to empty the table. TRUNCATE not only deletes the rows but resets the auto increment value by design. Use DELETE FROM table instead.
The TRUNCATE TABLE statement in MySQL completely deletes the table's data without removing a table's structure and always resets the auto-increment column value to zero.
ALTER TABLE suppliers AUTO_INCREMENT = 1; This example would change the next value in the AUTO_INCREMENT field (ie: next value in the sequence) to 1 for the supplier_id column in the suppliers table.
Look at this answer: Reorder / reset auto increment primary key
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With