FIX: Incorrect Identity Values After Failed Unique Index Creation

This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 351634 (SHILOH_bugs)
BUG #: 351180 (SHILOH_BUGS)
Symptoms
Inserts into a table may fail due to a "duplicate key values" message when all of the following are true:
  • A table exists with a UNIQUE INDEX or PRIMARY KEY defined.
  • The table contains a column with the IDENTITY property.
  • A CREATE INDEX statement is issued for an INDEX that already exists.
Cause
The failed CREATE INDEX statement resets the value for the IDENTITY column to its initial seed value.
Resolution
To resolve this problem, obtain the latest service pack for SQL Server 2000. For additional information, click the following article number to view the article in theMicrosoft Knowledge Base:
290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack
Workaround
Issue a DBCC CHECKIDENT statement after the failed index creation.
Status
Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.
More information
The following code reproduces the problem:
SET NOCOUNT ONUSE pubsGOcreate table IdentityRollbackTable (c1 nchar(30), id int identity (100,1))insert IdentityRollbackTable values('NoIndex1')insert IdentityRollbackTable values('NoIndex1')insert IdentityRollbackTable values('NoIndex2')insert IdentityRollbackTable values('NoIndex3')GO--/*'Should fail after first execution because of duplicate key.'*/ create unique clustered index IdentityRollbackIndex 	on IdentityRollbackTable(c1) WITH IGNORE_DUP_KEYGOinsert IdentityRollbackTable values('AfterFailedIndex1')insert IdentityRollbackTable values('AfterFailedIndex2')dbcc checkident(IdentityRollbackTable)insert IdentityRollbackTable values('AfterCheckIdent1')select * from IdentityRollbackTableGO drop table IdentityRollbackTableGO				
The results show that the identity value was incorrectly reinitialized to its seed value.
Server: Msg 1505, Level 16, State 1, Line 1CREATE UNIQUE INDEX terminated because a duplicate key was found for index ID 1. Most significant primary key is 'NoIndex1                      '.The statement has been terminated.Checking identity information: current identity value '101', current column value '103'.DBCC execution completed. If DBCC printed error messages, contact your system administrator.c1                             id          ------------------------------ ----------- NoIndex1                       100NoIndex1                       101NoIndex2                       102NoIndex3                       103AfterFailedIndex1              100AfterFailedIndex2              101AfterCheckIdent1               104				
Properties

Article ID: 290917 - Last Review: 01/16/2015 21:50:00 - Revision: 4.0

  • Microsoft SQL Server 2000 Standard Edition
  • kbnosurvey kbarchive kbbug kbfix kbsqlserv2000sp1fix KB290917
Feedback