如何防止MySQL重置自动增量值? [英] How to prevent mySQL from resetting auto increment value?

查看:109
本文介绍了如何防止MySQL重置自动增量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子来做临时的id.当我删除表的所有行时,此表的自动增量值将重置为0.但我不想重置自动增量. 我该怎么办?

I have a table to make temporary id`s . When i delete all of the rows of my table , auto increment value for this table will reset to 0 . but i don't want to reset the auto increment. What can i do?

推荐答案

比较

将任何AUTO_INCREMENT值重置为其初始值.这是真实的 即使对于MyISAM和InnoDB,通常不会重用序列 值.

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.

...和从以下位置删除:

如果您删除包含最大值的行 AUTO_INCREMENT列,该值不会再用于MyISAM或InnoDB 桌子.如果您使用DELETE FROM tbl_name删除表中的所有行 (没有WHERE子句)在自动提交模式下,序列从头开始 适用于除InnoDB和MyISAM之外的所有存储引擎.有一些 InnoDB表的此行为的异常,如本节所述 13.3.5.3,"InnoDB中的AUTO_INCREMENT处理".

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".

对于MyISAM表,可以指定一个AUTO_INCREMENT辅助列 在多列键中.在这种情况下,重复使用从中删除的值 即使对于MyISAM表,该序列的顶部也会出现.见章节 3.6.9,使用AUTO_INCREMENT".

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重置自动增量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆