[英]SQL Server identity column incrementing without insert
I have a C# console app which is using a stored procedure to insert rows into a SQL Server database. 我有一个C#控制台应用程序,它使用存储过程将行插入SQL Server数据库。 Currently the database has about 1m rows, however the ID column is up at 26m!
目前,数据库有大约1米的行,但ID列的最大长度为26米!
On the last successful insert the ID went from 16m to 26m. 在最后一次成功插入时,ID从16米到26米。 The app runs multiple threads in parallel so there is a chance it could be trying to insert two things at the same time.
该应用程序并行运行多个线程,因此有可能尝试同时插入两个东西。
Is there anything other than a transaction rollback that would cause the identity column to increment without adding a row? 除了事务回滚之外还有什么可以导致标识列在不添加行的情况下递增吗?
It seems unlikely that there were 10 million times that two threads tried to write a conflicting row at the same time. 似乎不太可能有两千个线程试图同时写一个冲突的行。
I'm using a temporary table variable which is populated by passing XML into the stored proc: 我正在使用一个临时表变量,它通过将XML传递到存储过程来填充:
-- insert data if it doesn-t already exist
insert into DataStore (DataText, DataSourceID)
select distinct td.dataText, td.dataSource
from @tempData td
where not exists ( select 'x'
from DataStore ds
where ds.DataText = td.dataText );
What can leave gaps? 什么可以留下空白?
I'd also check the increment value using IDENT_INCR in case it is really is 5 million or such 我还会使用IDENT_INCR检查增量值,以防它真的是500万或类似
Inserted and deleted record increments identity counter, as mentioned by @gbn - Rollbacks and c-violations also, but there is two more options: 插入和删除记录增量身份计数器,如@gbn所述 - 回滚和c违规,但还有两个选项:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.