FIX: Changing the data type and then updating the table with more than 4,000 records causes database corruption

Applies to: SQL Server 2012 DeveloperSQL Server 2012 EnterpriseSQL Server 2012 Enterprise Core

Symptoms


You change the data type of a column in a database table from ntext to nvarchar(max) on a server that is running Microsoft SQL Server 2012, 2014 or 2016. When you update the table by adding more than 4,000 records, DBCC CHECKDB may report errors that resemble the following:
 
Msg 8961, Level 16, State 1, LineNumber
Table error: ObjectID, indexID, partitionID, allocUnitID (type LOB data). The off-row data node at page (PageID), slot 0, textID does not match its reference from page (PageID), slot 0.

Msg 8961, Level 16, State 1, LineNumber
Table error: ObjectIDindexID, partitionID, allocUnitID (type LOB data). The off-row data node at page (PageID), slot 0, textID does not match its reference from page (PageID), slot 0.

Msg 8929, Level 16, State 1, LineNumber
ObjectID, indexID, partitionID, allocUnitID (type In-row data): Errors found in off-row data with ID owned by data record identified by RID = (RID)
DBCC results for 'TableName'.

There are 1 rows in 1 pages for object "TableName".
CHECKTABLE found 0 allocation errors and 3 consistency errors in table 'TableName' (ObjectID).
repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKTABLE (DatabaseName.TableName).
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Resolution


This issue is fixed in the following cumulative updates for SQL Server:
Cumulative Update 7 for SQL Server 2012 Service Pack 3

 

Workaround


To work around this issue after you change the data type, set the large value types out of row option to 1.
 
ALTER TABLE TableName ALTER COLUMN COLUMN_NAME nvarchar(max) NOT NULL goexec sp_tableoption 'TableName', 'large value types out of row', '1'

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

References


Learn about the terminology Microsoft uses to describe software updates.