The item_category_id column is auto increment value in the mysql table.
I need to delete all the values & next insertion should start from 1. If i delete all values & try to insert a new row then it starts with some 30's & 40's.
item_category_id item_category_name
1 qqq
25 ccc
32 vvv
29 bb
4 bbb
31 hhh
34 mmm
33 rrr
In MySQL, the syntax to change the starting value for an AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = start_value; table_name. The name of the table whose AUTO_INCREMENT value you wish to change.
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.
Using TRUNCATE TABLE Statement. 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 TABLENAME AUTO_INCREMENT = 1
Instead of using Delete if you use Truncate that will remove data and will also reset autoincrement.
TRUNCATE TABLE TABLENAME
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