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.
我刚刚注意到,如果我在表中有一个标识列,当我插入新行时,如果存在不连续性,SQL Server 2008会自动填充序列。我的意思是,如果在我的标识列中我有1,2,5,6,如果我在表中插入其他两行,系统会自动将3,7放入标识列。
Do you know how to control this behavior?
你知道如何控制这种行为吗?
THANKS
谢谢
1 个解决方案
#1
8
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??
这是已定义和记录的SQL Server行为,并且您无法对更改它做多少。你想改变什么?
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.
IDENTITY列将保证唯一的,不断增加的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不会遇到在序列中发现“间隙”并填写它们的麻烦。无论如何,我认为这不是一个好主意 - 如果你确实有ID = 3的记录,然后将其删除?你真的想要下一条记录突然“回收”那个ID吗?在我看来,这不是一个好主意。
#1
8
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??
这是已定义和记录的SQL Server行为,并且您无法对更改它做多少。你想改变什么?
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.
IDENTITY列将保证唯一的,不断增加的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不会遇到在序列中发现“间隙”并填写它们的麻烦。无论如何,我认为这不是一个好主意 - 如果你确实有ID = 3的记录,然后将其删除?你真的想要下一条记录突然“回收”那个ID吗?在我看来,这不是一个好主意。