mysql autoincrement restarts alone

Asked

Viewed 99 times

2

2 answers

1

Ali explains that TRUNCATE TABLE resets the Autoincrement fields of the table, and DELET FROM do not reset fields, even if you delete the line that contains the highest Autoincrement value will not be reset!

Review your codes you may be using Truncate!

1

Comparing TRUNCATE TABLE:

Any AUTO_INCREMENT value is reset to its initial value. This holds for both Myisam and Innodb, which usually does not occur with sequence values. DELETE FROM TABLE ...

If you delete the record containing the maximum ID "MAX(ID)", if it is an AUTO_INCREMENT column, the value will no longer be updated, either for Myisam or for Innodb. Now, if you delete all records from the table, with DELETE FROM TABLE (without using the WHERE clause) with the automatic confirmation mode, the sequence will be restarted on all Innodb storage engines except Myisam tables. There are some exceptions to this behavior for Innodb tables, as discussed in Section 13.3.5.3, "AUTO_INCREMENT maintenance for Innodb".

For Myisam tables, you can set a new AUTO_INCREMENT secondary column with a Multiple-column type key. This way, you can reuse the deleted values from the beginning of the sequence. See Section 3.6.9, "Use of AUTO_INCREMENT".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.