/ Published in: MySQL
- Scenario 1:
- If you have 100 rows, AND deleted the 100th row. The next auto increment value IS supposed to be 101. If you want the next auto increment value to be 100 instead, you can DO the following.
- ALTER TABLE tablename AUTO_INCREMENT = 1
- -- change "tablename" to the name of your table.
- Essentially, this ALTER statement will reset the next auto increment value to the existing largest value IN the auto increment COLUMN + 1
- Scenario 2:
- If you have 100 rows, AND deleted the 20th row. The next auto increment value IS supposed to be 101. However, if you want your next INSERT to be inserted as #20, you can use the follow “set” command immediately before your INSERT statement.
- SET insert_id = 20;
- Scenario 3:
- At last, if you simply want to wipe out the data THEN reset the auto increment back to start at 1, simply run:
- TRUNCATE TABLE tablename;
- This will DELETE all the data AND reset Auto Increment back to 1
You need to login to post a comment.