gpt4 book ai didi

MySQL 在自增列中使用静态数字是否安全

转载 作者:行者123 更新时间:2023-11-29 05:20:12 24 4
gpt4 key购买 nike

我在表中有一个自动递增的 ID 字段。它位于 13321。如果我有一些产品,我想插入并使用 15,000 到 15,500 行。

我在可以插入新数据的 Web 应用程序中有查询。这些查询都允许系统生成“id”字段,例如:

INSERT INTO mytable ('','value1', 'value2','value3')

如果我使用 15000 到 15500 插入我的静态数据,然后将我的自动增量 ID 重置回 13322,当系统达到 15000 时是否安全? MySQL 会知道跳到 15501 吗?

最佳答案

一旦您输入了 15000 到 15500 之间的值,表的 AUTO_INCREMENT 属性将设置为 15501。之后您无法将该属性重置回 13322(或任何其他小于或等于 15500 的值)。 Quote from MySQL manual :

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.

因此,MySQL 会知道跳到 15501 部分变得无关紧要了。

关于MySQL 在自增列中使用静态数字是否安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26844517/

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