FIX: Table Creation, Row Insertion, and Index Creation Inside Transaction, Followed By Addition of Constraint May Result in Consistency Errors

This article was previously published under Q286749
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 351939 (SHILOH_bugs)
SYMPTOMS
When you open a transaction, create a table, insert rows, create an index on the table, commit the transaction, and then add a constraint, a subsequent DBCC CHECKTABLE may report consistency errors. The DBCC CHECKTABLE may return results similar to:
Server: Msg 8970, Level 16, State 1, Line 2
Row error: Object ID 2041058307, index ID 0, page ID (1:77), row ID 0. Column 'LastModified' was created NOT NULL, but is NULL in the row.
Server: Msg 8970, Level 16, State 1, Line 2
Row error: Object ID 2041058307, index ID 0, page ID (1:77), row ID 1. Column 'LastModified' was created NOT NULL, but is NULL in the row.
Server: Msg 8970, Level 16, State 1, Line 2
Row error: Object ID 2041058307, index ID 0, page ID (1:77), row ID 2. Column 'LastModified' was created NOT NULL, but is NULL in the row.
DBCC results for '#TableX_____________________________000000000011'.
There are 0 rows in 1 pages for object '#TableX______________________________________________000000000011'.
CHECKTABLE found 0 allocation errors and 3 consistency errors in table '#TableX________________________000000000011' (object ID 2041058307).
repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKTABLE (tempdb.dbo.#TableX________________________________________000000000011 ).

A message similar to the following is logged in the SQL Server error log:
(tempdb.dbo.#TableX______________________________000000000011) executed by <DOMAIN>\<user> found 3 errors and repaired 0 errors.
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
To work around this problem, use any of the following methods:
  • Create the index after you commit the transaction.
  • Insert a value into the table after you create the index and before you close the transaction.
  • Insert a value into the table after you commit the transaction and before you add the constraint.
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
To reproduce the problem, run the following script:
begin trancreate table #TableX (Col1 varchar(20))insert #TableX values ('A')insert #TableX values ('B')insert #TableX values ('C')create index ix_Col1 on #TableX(Col1)  -- works fine when this is moved after the commit--insert #TableX values ('D') -- or when this is uncommentedcommit--insert #TableX values ('D') -- or when this is uncommentedalter table #TableX add LastModified datetime not null constraint cn_Enabled default getdate()goselect * from #TableXdbcc checktable(#TableX)godrop table #TableX				
Properties

Article ID: 286749 - Last Review: 01/16/2015 21:30:01 - Revision: 3.2

Microsoft SQL Server 2000 Standard Edition

  • kbnosurvey kbarchive kbbug kbfix kbsqlserv2000sp1fix KB286749
Feedback