如果达到限制,数据库如何处理自动编号字段?
在我的表中,我选择了 id 列的类型为 int (4 字节)。我想知道的答案是,一旦达到限制,任何数据库将如何处理它?数据库会拒绝在表中插入更多记录吗?或者到底会发生什么?另外我应该如何解决此类问题(如果数据库本身不能处理它)?
In my tables, i have selected id column to be of type int (4 bytes). The answer i want to know is how will any database handle it once it's limits are reached? Will the database refuse to insert any more records in table? or what exactly will happen? Also how should i tackle this type of problem (if the database doesn't handle it by itself)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很想知道您所说的“数据库”是什么。但通常这是一个错误。那么数据库就满了。您应该提供一些“压缩”主键的方法,或者更简单:
使用长整数作为键(8 字节)。即使从现在开始每秒插入 1000 个项目,这也会持续近 3 亿年。在这种情况下,4 字节整数(带符号)仅持续 24 天。
I would love to know what you refer to as "the" database. But usually it is an error. The database is full then. You should provide some means for "compacting" the primary key then, or more easy:
Use long integers as keys (8 bytes). Even if you insert 1000 items per second from now on, this will last for nearly 300 million years. The 4 byte integer (signed) will only last for 24 days in this scenario.