Reset Auto-Increment In MySql

mysqlIn this post i going to demonstrate how to reset auto-increment value in MySql. There is no doubt MySQL provides an awesome feature called auto-increment. We assign the auto-increment attribute to a column of a table. Every time new row is inserted it increments the value. By default the auto-increment column is primary key of a table.

Some times you want to reset auto-increment value in mysql

Subscribe Our Tutorials

Get Latest Updates on Facebook

To illustrate this let’s create one dummy table

Insert some dummy value

Now table is created and three rows inserted into it.

Let’s check Delete all the records . To Delete the data run

Now if you insert any new value it auto-increment the value to 4.

How to Reset Auto-Increment In MySql

1. Reset MySql Auto-increment through Alter Command.

It resets the auto-increment value to 1. So can specify any other value as well.

2. Using Truncate.

The TRUNCATE TABLE statement removes all the data of a table and reset auto-increment value to zero. T

Hope these two tips are very helpful to reset the auto-increment value. If you find any other methods you can share it through comments.


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.