Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reset Auto increment values in mysql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 339
    Comment on it

    To reset the auto-increment values you can apply any one of the method given below:

    1. Auto increment value can be reset by using alter table statement. Syntax to reset auto-increment value is as follows:
    2. ALTER TABLE table_name AUTO_INCREMENT = value;
      

      Suppose you have created a table 'demo' with data as follows(id is auto-increment field):

      id name
      1 name1
      2 name2
      3 name3

      In above table, if you delete the field with id=3 and again insert a row it will assign 4 to id. You can reset the id by using alter table statement as follows:

      ALTER TABLE demo AUTO_INCREMENT = 3;
      

      To reset the value keep one thing in mind the value should be greater than or equal to the current maximun value.

    3. TRUNCATE TABLE statement removes all the data of a table and reset auto-increment value to zero.
    4. TRUNCATE TABLE table_name;
      

 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: