Hello friends, I was facing issue in database. I wanted the auto increment should start from 1.
There were 20 rows in table. When I deleted all the rows from the table and inserted new row then auto increment started from id = 21 instead of 1. I wanted to start counting from 1 again. This issue was resolved by following lines :
ALTER TABLE tablename AUTO_INCREMENT = 1
For InnoDB you cannot set the auto_increment
value lower or equal to the highest current index.
This is the sample example: Here you can see that I am deleting records from table user_invites having 5 rows in it.
![](http://findnerd.s3.amazonaws.com/imagedata/4355/4355.png)
5 rows have been deleted as shown below:
![](http://findnerd.s3.amazonaws.com/imagedata/4354/4354.png)
Now I inserted one row into the table user_invites:
![](http://findnerd.s3.amazonaws.com/imagedata/4356/4356.png)
Now you will see that instead of starting from id 1, it is starting from id 27
![](http://findnerd.s3.amazonaws.com/imagedata/4358/4358.png)
Now lets reset auto increment
![](http://findnerd.s3.amazonaws.com/imagedata/4359/4359.png)
Now lets insert 1 row again
![](http://findnerd.s3.amazonaws.com/imagedata/4360/4360.png)
Now you will see that auto increment has been reset to 1
![](http://findnerd.s3.amazonaws.com/imagedata/4361/4361.png)
Thanks for reading the blog.
0 Comment(s)