Change the auto increment value in MySQL

Change the auto increment column in Mysql

We can change the value of auto increment column which set by getting the maximum value from the table. Suppose we did lot of delete operation and we want to set the auto increment again but we need to fine first max value present in table then we change it.

Find the max value for the column

select max(column_name) from table_name;

Set the Auto increment value for the table, suppose max return 100 then plus 1 for new value.

ALTER TABLE table_name AUTO_INCREMENT = 101;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.