到达自动生成 (IDENTITY) 字段的值池末尾

发布于 2024-11-15 08:52:17 字数 658 浏览 3 评论 0原文

大多数数据库支持 INT 字段的自动生成,主要用作该表的键。它有时被设置为简称为id

假设程序需要多长时间才能使 C# int 和数据库 INT 值不再相互支持,或者 INT 值用完需要多长时间,或者有多大这个为数据库自动生成的 id 字段,比如 sqlite?

当你尝试插入一条新记录,并且数据库自动生成的行ID用完时,会发生什么;不再插入吗?

谢谢

[编辑]

您是否偶尔查看表的 ID 值?

大多数人不知道,如果由于某种原因您的应用进行了大量插入和删除操作,那么每次插入时都会生成一个新的 ID 值。数据库似乎不会重用已删除的ID,因此在这种情况下,如果应用程序进行大量插入和删除操作,只有1000 记录的数据库可能会用完该值! !

我问这个问题的原因是,通常在您经常使用 ID 值的应用程序中来跟踪记录;我总是这样做。

以免说我做了这样的事情,

int record_id= reader("id").value;

我什么时候会收到溢出错误? 数据库INT在所有编程环境中都与int相同吗?

Most database support autogenerate for an INT field, mostly used as the key for that table. It sometimes is set named id for short.

how much time before the program lets say c# int and the database INT value no longer support each other, or how long before the INT value is used up, or how large is this auto generated id field for a database, lets say sqlite?

When you try to insert a new record, and the data base auto generated row id is used up, what happens; no more insert?

thanks

[EDIT]

Do you look at the ID values of your tables once in a while?

Most people don't know that if for some reason you app does alot of insert and delete, then a new ID value is generated each time you insert. is seems that databases does not reuse deleted ID, so in that case a database with just 1000 records can use up that value if the app does alot of insert and deleteing!!!

The reason i asked this question is this, normally in apps you frequently make use of the ID value, to keep track of records; i do always.

lest say i did somthing like this

int record_id= reader("id").value;

when will i get an overflow error?
is the database INT the same as int in all programing environment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔 2024-11-22 08:52:18

我不了解 sqlite,但对于 SQL Server,最大值如下所示:

max int (32 bit) = 2,147,483,647
max bigint (64 bit) = 9,223,372,036,854,775,807

如果在某个时刻您用完了值范围,则尝试插入新记录将失败。它会说以下内容:

将 IDENTITY 转换为数据类型 int 时出现算术溢出错误。发生算术溢出。

同样,我不知道 sqlite,但在 SQL Server 中,失败的事务也会消耗池中的值。如果您尝试插入并且包含事务回滚,则生成的 IDENTITY 值将不会返回到池中。如果您的交易经常失败,那么这也会浪费一定比例(尽管非常小)的价值。

sqlite 很可能以类似的方式工作。

I don't know about sqlite but for the SQL Server the maximum values look like this:

max int (32 bit) = 2,147,483,647
max bigint (64 bit) = 9,223,372,036,854,775,807

If at some point you've used up the value range then an attempt to insert a new record will fail. It will say the following:

Arithmetic overflow error converting IDENTITY to data type int. Arithmetic overflow occurred.

Again, have no idea about sqlite but in SQL Server the failed transactions will also consume a value from the pool. If you attempt an insert and the containing transaction is rolled back then the generated IDENTITY value will not be returned to the pool. If you have transactions failing regularly then that will also waste a certain ( though very small) percentage of the values.

Most likely sqlite works in a similar way.

肤浅与狂妄 2024-11-22 08:52:18

SQLite 中 INT 的最大大小是 8 字节,这是一个非常非常大的数字。我发现很难想象一个使用 SQLite 的应用程序实际上可能“用完”INT。为了实现这一点,您必须运行一些非常大的数据仓库系统,而使用 SQLite 则不会这样做。所以不用担心!

The maximum size for an INT in SQLite is 8-bytes, which is a very, very big number. I find it hard to imagine an application which used SQLite where you could actually "run out" of INTs. You would have to be running some very large data-warehousing system for this to happen, which you are not going to be doing with SQLite. So don't worry!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文