mysql set auto increment to 1 code example

Example 1: mysql reset auto increment value

ALTER TABLE table_name AUTO_INCREMENT = 1;

Example 2: mysql reset auto increment id

SET  @num := 0;

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

ALTER TABLE your_table AUTO_INCREMENT =1;

Example 3: mysql set id auto increment

ALTER TABLE users AUTO_INCREMENT=1001;

Example 4: add auto_increment column to existing table mysql

ALTER TABLE `users` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY

ALTER TABLE `users` ADD `id` INT NOT NULL AUTO_INCREMENT UNIQUE FIRST

Example 5: auto_increment mysql

ALTER TABLE User AUTO_INCREMENT = 1;

Example 6: mysql reset auto increment to 1

ALTER TABLE tablename AUTO_INCREMENT = 1

Tags:

Sql Example