twan
twan

Reputation: 2659

Change auto_increment value on existing table in MYSQL

Is there a way to change the auto increment value? What I need is a value to be lowered because for some reason there is a bug in my database.

Two id's should match, but the auto incremented id is always one more.

Is it possible to lower it by 1 on an existing table? (MYSQL/phpmyadmin)

Upvotes: 1

Views: 3174

Answers (2)

Navnath
Navnath

Reputation: 133

You can reset the counter with:

For InnoDB you cannot set the auto_increment value lower or equal to the highest current index.

Note that 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. See How to Reset an MySQL AutoIncrement using a MAX value from another table? on how to dynamically get an acceptable value.

Source :-- stackoverflow

Upvotes: 1

Jan Petr
Jan Petr

Reputation: 705

Yes, it is possible in MySQL. In you PhpMyAdmin select your table, go to "Operations" tab and there is "auto increment" option where you can set new auto increment value.

But remember it can break down your whole database and it's definitely not recommended to mess with auto increments.

Upvotes: 1

Related Questions