Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Workbench - Altering Next Auto Increment Value does not Work

I am trying to change what the next auto increment value will be for a given table using MySQL workbench. The next auto increment value is currently set to 3, and I am trying to make it 2. Whenever I try to apply the changes, the workbench runs the following code.

ALTER TABLE `mysql_schema`.`mysql_table` 
AUTO_INCREMENT = 2 ;

After running this code however, the change is not applied, and the next auto increment value is still three. What's the problem? Why is the auto increment value not changing? I have tried to manually execute the code, but it did not work either.

like image 507
DaveTheMinion Avatar asked Oct 27 '25 09:10

DaveTheMinion


2 Answers

I know this answer is a long time after the initial request, but it may help out people with the same problem.

So, you had two rows, deleted one of them and the next increment value is 3. To change this '3' to '2' and allow future incremental values to flow from '2' and not '3', please try the following.

From the 'Schemas' column (on the left):

  • Right-click on the table name.
  • Select 'Alter Table' (or press the 'spanner' icon).
  • Look down to the 'grey area' that has the 'Apply' and 'Revert' buttons
  • On the left of this 'grey area' are 6 tabs.
  • One of these tabs is the 'Options' tab - Select the Options tab.
  • In the 'General Options' section is an 'Auto Increment' box
  • Type '2' into the 'Auto Increment' box and press the 'Apply' button.
  • In the resultant box, press 'Apply' and then the 'Finish' buttons.
  • Return to your table and add a new row and press the Apply button.
  • The value of incremental column will now be '2'.

I hope this works for you.

like image 54
Alan N Avatar answered Oct 30 '25 01:10

Alan N


You cannot reset the counter to a value less than or equal to any that have already been used.
For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one.
For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

MySQL official alter doc

like image 27
Up_One Avatar answered Oct 30 '25 00:10

Up_One



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!