How To Reset AUTO_INCREMENT In MySQL?


1
Listing Type
List Category
Tutorials
Location
Bur Dubai
Last update

Directly Reset Auto increment Value :-


ALTER TABLE tablename AUTO_INCREMENT = 1

Note:- Before running this query Data( Records ) must & should empty then it will work. if Data ( Records ) is available so this method doesn't
work .This Query should not work for InnoDB.

Truncate Table :- Truncate table automatically reset the Auto increment values to 0.


TRUNCATE TABLE table_name;

Drop & Recreate Table :- This is another way of resetting auto increment index.


Note:- dnt use this method

SET @num := 0;

UPDATE Tablename SET id = @num := (@num+1);

ALTER TABLE Tablename AUTO_INCREMENT =1;

OR

ALTER TABLE Tablename DROP fieldname

ALTER TABLE Tablename ADD fieldname int(10) NOT NULL AUTO_INCREMENT ,ADD PRIMARY KEY (field name)

Note :- This Query should also work with InnoDB.
Distance Education In Dubai
Dubai, United Arab Emirates

9966416345
REPLY TO THIS CLASSIFIED
9 + 3 =