Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to reset AUTO_INCREMENT in MySQL?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 7
    • 0
    • 1.86k
    Comment on it

    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.

     

     

    5 rows have been deleted as shown below:

     

     

    Now I inserted one row into the table user_invites:

     

     

    Now you will see that instead of starting from id 1, it is starting from id 27

     

     

    Now lets reset auto increment

     

     

    Now lets insert 1 row again

     

     

    Now you will see that auto increment has been reset to 1

     

     

    Thanks for reading the blog.

     

     

    How to reset AUTO_INCREMENT in MySQL?

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: