主键列增加错误的增量值 [英] Primary key column is incremented by wrong increment value

查看:75
本文介绍了主键列增加错误的增量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的数据库中的表遇到了一个奇怪的问题。

我的应用程序中的表是使用主数据库创建的key defined(带聚簇索引)。

身份种子是我数据库中所有表的一个(IDENTITY(1,1))。



使用从ADO.net Windows应用程序调用的存储过程在这些数据库上完成CRUD操作。我在这里面临的问题是有时主键的值增加1000或10000而我无法弄清楚原因。
这里有一些表格

for Ex。在值170142之后,SQL服务器使用180141,或者在5025使用主键6025后的某个时间由SQL选择

Hello ,

I am facing a weird issue with tables in my database.
Tables in my application are created with a primary key defined (with Clustered index).
Identity seed is a one for all tables in my database (IDENTITY(1,1)).

CRUD operations are done on these databases using stored procedure which are called from an ADO.net windows application. The problem i am facing here is sometimes values of primary key is incremented by 1000 or 10000 and i not able to figure out why.
here are some tables
for Ex. here after values 170142 , 180141 is used by SQL server or sometime after 5025 vale of primary key 6025 is choosen by SQL

170139
170140
170141
170142
180141
180142
180143
180144
190141
190142
190143
190144





我检查过这些表的身份种子和增量值但是它似乎是有序的。记录之间没有任何内容被删除。



有没有人遇到类似情况?

非常感谢你的帮助。

谢谢。



I have checked identity seed and increment values for these tables but it seems to be in order. and none of the in between records are deleted.

Have anybody encountered similar scenarios?
Your help is much appreciated.
Thanks.

推荐答案

从未见过或听说过这个问题:我经常使用SQL身份字段,我很确定它会显示出来。



你确定这正是发生的事吗?例如,删除行会很容易看到这种变化,因为身份值不会被重复使用。

插入5行:

Never seen or heard of that as a problem: and SQL Identity fields are used so often I'm pretty sure it would show up.

Are you sure that is exactly what is happening? It would be easy to see that kind of change if rows are deleted for example, since the identity values will not be reused.
Insert 5 rows:
INSERT INTO MyTable (desc) VALUES ('One') ('Two') ('Three') ('Four') ('Five')

给你:

Gives you:

1 One
2 Two
3 Three
4 Four
5 Five

然后删除几个:

Then delete a couple:

DELETE FROM MyTable WHERE id IN (2, 4, 5)

并添加更多:

And add a couple more:

INSERT INTO MyTable (desc) VALUES ('New') ('And again')

你最终得到:

And you end up with:

1 One
3 Three
6 New
7 And again


您可以在这里找到答案。 。



[ ^ ]
You might find your answer here..

[^]


SQL Server 2012自动标识列值跳转问题 [ ^ ]


这篇关于主键列增加错误的增量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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