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

Article translations Article translations
Article ID: 286749 - View products that this article applies to.
This article was previously published under Q286749
BUG #: 351939 (SHILOH_bugs)
Expand all | Collapse all

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 the Microsoft 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 tran
create 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 uncommented
commit

--insert #TableX values ('D') -- or when this is uncommented

alter table #TableX add LastModified datetime not null constraint cn_Enabled default getdate()
go
select * from #TableX
dbcc checktable(#TableX)
go
drop table #TableX
				

Properties

Article ID: 286749 - Last Review: October 17, 2003 - Revision: 3.2
APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv2000sp1fix KB286749

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com