SQL Server和“身份"列中的差距 [英] SQL Server and gaps in an Identity column

查看:52
本文介绍了SQL Server和“身份"列中的差距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是注意到,如果表中有一个Identity列,则在我插入新行时,如果存在不连续性,SQL Server 2008会自动填充该序列.我的意思是,如果我在身份列中有1,2,5,6(如果我在表中插入其他两行),系统会自动在身份列中放入 3 ,7.

I just noticed that if I have an identity column in a table, when I insert new rows SQL Server 2008 is automatically filling up the sequence if there are discontinuity. I mean, if in my identity column I have 1,2,5,6 if I insert other two rows in the table the system puts automatically 3,7 in the identity column.

您知道如何控制这种行为吗?

Do you know how to control this behavior?

谢谢

推荐答案

这是已定义并记录在案的SQL Server行为,对于更改它,您实际上无能为力.您想对此进行哪些更改?

That is the defined and documented SQL Server behavior, and there's really not much you can do about changing it. What did you want to change about it??

IDENTITY列将确保唯一且不断增加的ID(只要您不搞乱它们)-他们不保证其他任何事情.

IDENTITY columns will guarantee unique, ever-increasing ID's (as long as you don't mess around with them) - they don't guarantee anything else.

SQL Server将会遇到在序列中发现空白"并填满它们的麻烦.无论如何,我认为这不是一个好主意-如果您确实有ID = 3的记录,然后将其删除怎么办?您是否真的要下一条记录突然回收"该ID?我认为这不是一个好主意.

SQL Server will not go through the trouble of spotting "gaps" in your sequence and filling them up. I don't think that would be a good idea, anyway - what if you did have a record with ID=3, and then deleted it? Do you really want a next record to suddenly "recycle" that ID?? Not a good idea, in my opinion.

这篇关于SQL Server和“身份"列中的差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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