How do I change the Auto Increment counter in MySQL?
ALTER TABLE table_name AUTO_INCREMENT=310;
Beware though, you don't want to repeat an ID. If the numbers are that high, they got that way somehow. Be very sure you don't have associated data with the lower ID numbers.
https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html
There may be a quicker way, but this is how I would do it to be sure I am recreating the IDs;
If you are using MySQL or some other SQL server, you will need to:
- Backup your database
- Drop the id column
- Export the data
TRUNCATE
or 'Empty' the table- Recreate the
id
column asauto_increment
- Reimport the data
This will destroy the IDs of the existing rows, so if these are important, it is not a viable option.
The auto increment counter for a table can be (re)set two ways:
By executing a query, like others already explained:
ALTER TABLE <table_name> AUTO_INCREMENT=<table_id>;
Using Workbench or other visual database design tool. I am gonna show in Workbench how it is done - but it shouldn't be much different in other tool as well. By right click over the desired table and choosing
Alter table
from the context menu. On the bottom you can see all the available options for altering a table. ChooseOptions
and you will get this form:Then just set the desired value in the field
Auto increment
as shown in the image. This will basically execute the query shown in the first option.