SQLSERVER标识列值跳过数百万

时间:2016-09-07 09:42:18

标签: sql sql-server identity identity-column

我有一个带有int标识列的表,它有时会跳过成千上万的id。搜索建议sql server跳过1000或1001是正常的,但有时会增加20000或更多,但上次它被 95216000 跳了。

无法找到发生这种情况的原因,请检查sql server是否有崩溃日志和任何其他可疑事件,但没有运气。

在桌面上复制,是相关的.. ??

创建表脚本就像..

CREATE TABLE [dbo].[Table](
    [CId] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    .
    .
    .

 CONSTRAINT [PK_Table] PRIMARY KEY CLUSTERED 
(
    [CId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
GO

2 个答案:

答案 0 :(得分:0)

您是否检查了此

的值
SELECT IDENT_SEED(TABLE_NAME) AS Seed,
IDENT_INCR(TABLE_NAME) AS Increment,
IDENT_CURRENT(TABLE_NAME) AS Current_Identity,
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'YourTableName') = 1
AND TABLE_TYPE = 'BASE TABLE'

您是否有可能将数据截断为表格?

答案 1 :(得分:0)

请参阅此链接以找出差距的原因。

http://sqlity.net/en/792/the-gap-in-the-identity-value-sequence/