To reset the auto-increment values you can apply any one of the method given below:
- Auto increment value can be reset by using alter table statement. Syntax to reset auto-increment value is as follows:
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.
- TRUNCATE TABLE statement removes all the data of a table and reset auto-increment value to zero.
TRUNCATE TABLE table_name;
0 Comment(s)