Reputation: 1151
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
Upvotes: 14
Views: 25990
Reputation: 4718
SET @num := 0;
UPDATE your_table SET id = @num := (@num+1);
ALTER TABLE your_table AUTO_INCREMENT =1;
I think this will do it
Upvotes: 3
Reputation: 1622
If you're using PHPmyAdmin to manage your database, you could simply
YOUR_TABLE
More
Operations
AUTO_INCREMENT
field that you can alter:Upvotes: 8
Reputation: 8461
Reset the auto increment value for a MySQL table
ALTER TABLE `users` AUTO_INCREMENT = 1;
Upvotes: 5
Reputation: 20323
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
Upvotes: 36