gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:37:12 25 4
gpt4 key购买 nike

我有一个表来制作临时 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com