database - 当整数列上的 auto_increment 达到数据库中的 max_value 时会发生什么?

标签 database auto-increment integer-overflow lastinsertid

我正在实现一个数据库应用程序,我将使用 JavaDB 和 MySQL 作为数据库。我的表中有一个 ID 列,它的类型是整数,我使用数据库的 auto_increment-function 作为值。

但是当我收到超过 2(或 4)亿个帖子并且整数不够时会发生什么?整数是溢出并继续还是抛出我可以处理的异常?

是的,我可以更改为 long as 数据类型,但我如何检查何时需要它?而且我认为如果我使用 long 作为 ID 列的数据类型,那么获取 last_inserted_id() 函数会有问题。

最佳答案

Jim Martin 来自 §3.6.9. "Using AUTO_INCREMENT" 的评论MySQL 文档:

Just in case there's any question, the AUTO_INCREMENT field /DOES NOT WRAP/. Once you hit the limit for the field size, INSERTs generate an error. (As per Jeremy Cole)

使用 MySQL 5.1.45 的快速测试导致错误:

ERROR 1467 (HY000): Failed to read auto-increment value from storage engine

您可以在插入时测试该错误并采取适当的措施。

关于database - 当整数列上的 auto_increment 达到数据库中的 max_value 时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2615417/

相关文章:

php - 如何在数据库的单个列中保存多个复选框值并使用 laravel 检索它

MySQL 存储过程乘法

mysql - mysql查询中的for循环功能

sql - 通过 psql 和 PuTTY 连接到 Postgres 时出现自动递增错误

delphi - 通过ADO连接时如何获取AUTOINC值?

c - 当 C 表达式中发生整数溢出时会发生什么?

c - 二进制编辑导致删除先前添加的二进制数

php - 在mysql中动态更改字段顺序

c++ - 如何检测无符号整数溢出?

postgresql - 在 PostgreSQL 中生成自动递增主键的可接受方法是什么?