How to reset AUTO_INCREMENT in MySQL?

homerun

How can I reset the AUTO_INCREMENT of a field?
I want it to start counting from 1 again.

Niels

You can reset the counter with:

ALTER TABLE tablename AUTO_INCREMENT = 1

For InnoDB you cannot set the auto_increment value lower or equal to the highest current index. (quote from ViralPatel):

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AUTO_INCREMENT on UPDATE in MySql

From Dev

How can I update an existing record to have a new auto_increment id in MySQL?

From Dev

MySQL AUTO_INCREMENT according to year

From Dev

MySQL INSERT INTO SELECT into a table with AUTO_INCREMENT

From Dev

MySQL, AUTO_INCREMENT, and NOT NULL

From Dev

How to assign a AUTO_INCREMENT value in rails

From Dev

Reset auto_increment based on datetime column

From Dev

MySQL Insert/Update Trigger with AUTO_INCREMENT

From Dev

How do I Implement AUTO_INCREMENT in a Yii2 Migration Using MySQL?

From Dev

how to reset the value of a AUTO_INCREMENT row in a mysql table

From Dev

Hibernate auto_increment MySQL

From Dev

How to implement an auto_increment composite primary key with MySQL InnoDB?

From Dev

AUTO_INCREMENT in mysql can be signed by default?

From Dev

How to find if a column is auto_increment in MySQL

From Dev

Nagios: monitor mysql auto_increment overflow

From Dev

How can I update an existing record to have a new auto_increment id in MySQL?

From Dev

Reset auto_increment after deleting row

From Dev

mySQL adding rows to an auto_increment column

From Dev

MySQL, AUTO_INCREMENT, and NOT NULL

From Dev

How to set AUTO_INCREMENT default value and rate of increase in MySQL 5.6

From Dev

MySQL ALTER TABLE AUTO_INCREMENT and ORDER BY

From Dev

How to reset the AUTO_INCREMENT

From Dev

how to reset the value of a AUTO_INCREMENT row in a mysql table

From Dev

Reset Auto_Increment Value After Data Delete MySQL

From Dev

Hibernate auto_increment MySQL

From Dev

mySQL AUTO_INCREMENT column creation

From Dev

How to implement an auto_increment composite primary key with MySQL InnoDB?

From Dev

Reset auto_increment in insert into statement

From Dev

How to reset AUTO_INCREMENT in MySQL for all tables within a DB?

Related Related

  1. 1

    AUTO_INCREMENT on UPDATE in MySql

  2. 2

    How can I update an existing record to have a new auto_increment id in MySQL?

  3. 3

    MySQL AUTO_INCREMENT according to year

  4. 4

    MySQL INSERT INTO SELECT into a table with AUTO_INCREMENT

  5. 5

    MySQL, AUTO_INCREMENT, and NOT NULL

  6. 6

    How to assign a AUTO_INCREMENT value in rails

  7. 7

    Reset auto_increment based on datetime column

  8. 8

    MySQL Insert/Update Trigger with AUTO_INCREMENT

  9. 9

    How do I Implement AUTO_INCREMENT in a Yii2 Migration Using MySQL?

  10. 10

    how to reset the value of a AUTO_INCREMENT row in a mysql table

  11. 11

    Hibernate auto_increment MySQL

  12. 12

    How to implement an auto_increment composite primary key with MySQL InnoDB?

  13. 13

    AUTO_INCREMENT in mysql can be signed by default?

  14. 14

    How to find if a column is auto_increment in MySQL

  15. 15

    Nagios: monitor mysql auto_increment overflow

  16. 16

    How can I update an existing record to have a new auto_increment id in MySQL?

  17. 17

    Reset auto_increment after deleting row

  18. 18

    mySQL adding rows to an auto_increment column

  19. 19

    MySQL, AUTO_INCREMENT, and NOT NULL

  20. 20

    How to set AUTO_INCREMENT default value and rate of increase in MySQL 5.6

  21. 21

    MySQL ALTER TABLE AUTO_INCREMENT and ORDER BY

  22. 22

    How to reset the AUTO_INCREMENT

  23. 23

    how to reset the value of a AUTO_INCREMENT row in a mysql table

  24. 24

    Reset Auto_Increment Value After Data Delete MySQL

  25. 25

    Hibernate auto_increment MySQL

  26. 26

    mySQL AUTO_INCREMENT column creation

  27. 27

    How to implement an auto_increment composite primary key with MySQL InnoDB?

  28. 28

    Reset auto_increment in insert into statement

  29. 29

    How to reset AUTO_INCREMENT in MySQL for all tables within a DB?

HotTag

Archive