SQLite数据库中的标识列最大值 [英] Identity column maximum value in SQLite DBs

查看:168
本文介绍了SQLite数据库中的标识列最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于SQLite数据库的纯学术问题。



我使用SQLite.net在我的WinForm项目中使用数据库,新表,我想到了ID列的最大值。



我使用 IDENTITY [ID] 列,根据 SQLite.net DataType映射,等同于 DbType.Int64 。我通常将ID列开始为零(将该行作为测试记录),并让数据库自动递增。



最大值( Int64.MaxValue )为9,223,372,036,854,775,807。为了我的目的,我永远不会在达到最大值时刮伤表面,但是在数据库中会发生什么?在尝试阅读时,我发现DB2显然将值包装为负值(-9,223,372,036,854,775,807),并从那里递增,直到数据库无法插入行,因为ID列必须是唯一的。 / p>

这是在SQLite和/或其他数据库引擎中发生的吗?

解决方案

p>我怀疑任何人都知道肯定,因为如果每秒100万行被插入,将需要大约292,471年来达到环绕风险点 - 数据库已经在这段时间的一小部分实际上,也有智人; - )。


I have a purely academic question about SQLite databases.

I am using SQLite.net to use a database in my WinForm project, and as I was setting up a new table, I got to thinking about the maximum values of an ID column.

I use the IDENTITY for my [ID] column, which according to SQLite.net DataType Mappings, is equivalent to DbType.Int64. I normally start my ID columns at zero (with that row as a test record) and have the database auto-increment.

The maximum value (Int64.MaxValue) is 9,223,372,036,854,775,807. For my purposes, I'll never even scratch the surface on reaching that maximum, but what happens in a database that does? While trying to read up on this, I found that DB2 apparently "wraps" the value around to the negative value (-9,223,372,036,854,775,807) and increments from there, until the database can't insert rows because the ID column has to be unique.

Is this what happens in SQLite and/or other database engines?

解决方案

I doubt anybody knows for sure, because if a million rows per second were being inserted, it would take about 292,471 years to reach the wrap-around-risk point -- and databases have been around for a tiny fraction of that time (actually, so has Homo Sapiens;-).

这篇关于SQLite数据库中的标识列最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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