当整数列上的auto_increment达到数据库中的max_value时,会发生什么? [英] What happens when auto_increment on integer column reaches the max_value in databases?

查看:162
本文介绍了当整数列上的auto_increment达到数据库中的max_value时,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am implementing a database application and I will use both JavaDB and MySQL as database. I have an ID column in my tables that has integer as type and I use the databases auto_increment-function for the value.

但是,当我获得超过2或4)十亿个职位和整数还不够吗?是整数溢出并继续还是抛出一个异常,我可以处理?

But what happens when I get more than 2 (or 4) billion posts and integer is not enough? Is the integer overflowed and continues or is an exception thrown that I can handle?

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

Yes, I could change to long as datatype, but how do I check when that is needed? And I think there is problem with getting the last_inserted_id()-functions if I use long as datatype for the ID-column.

推荐答案

Jim Martin对§3.6.9的评论。 使用AUTO_INCREMENT的MySQL文档:

Jim Martin's comment from §3.6.9. "Using AUTO_INCREMENT" of the MySQL documentation:


只要有任何问题,AUTO_INCREMENT字段/ DOES NOT WRAP / 。一旦您达到字段大小的限制,INSERT会生成错误。 (按照Jeremy Cole)

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的快速测试导致错误:

A quick test with MySQL 5.1.45 results in an error of:


错误1467(HY000):无法从存储引擎读取自动递增值

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


$ b b

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

You could test for that error on insert and take appropriate action.

这篇关于当整数列上的auto_increment达到数据库中的max_value时,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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