mysql - 如何防止mySQL重置自动增量值?

标签 mysql auto-increment reset

我有一个表来制作临时 id`s。当我删除表中的所有行时,该表的自动增量值将重置为 0。但我不想重置自动增量。 我能做什么?

最佳答案

比较 TRUNCATE TABLE :

Any AUTO_INCREMENT value is reset to its start value. This is true even for MyISAM and InnoDB, which normally do not reuse sequence values.

... 与 DELETE FROM :

If you delete the row containing the maximum value for an AUTO_INCREMENT column, the value is not reused for a MyISAM or InnoDB table. If you delete all rows in the table with DELETE FROM tbl_name (without a WHERE clause) in autocommit mode, the sequence starts over for all storage engines except InnoDB and MyISAM. There are some exceptions to this behavior for InnoDB tables, as discussed in Section 13.3.5.3, “AUTO_INCREMENT Handling in InnoDB”.

For MyISAM tables, you can specify an AUTO_INCREMENT secondary column in a multiple-column key. In this case, reuse of values deleted from the top of the sequence occurs even for MyISAM tables. See Section 3.6.9, “Using AUTO_INCREMENT”.

关于mysql - 如何防止mySQL重置自动增量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8823877/

相关文章:

PHP/MySQL 时间戳和时区

CSS 重置 : font-size: 100%; Why?

mysql - 在自增字段前自动添加字母

php - AUTO_INCRMENT 和 CURRENT_TIMESTAMP 协同工作的复合键

jquery - 如何使jquery计算器刚刚执行计算后不追加数字?

redmine - 是否有重置 Redmine 管理员密码的 rake 命令?

mysql - 在 mysql 中使用 concat() 的准备语句给出错误

mysql - Insert table into another table conditionally - insert into select 案例

mysql - 使用连接表列值的总和更新 mysql 表列?

sql-server - 如果我有一个只有自动增量列的表,我该如何插入?