The type of SQL Server 2005 MSG 2570 is "In-row data". Column values are beyond the range of data types

Keywords: SQL Database

When checking the consistency of the database, the following problems arise:

DBCC CHECKDB(MyDB)
DBCC CHECKTABLE (MyTable)
/*
MyTable DBCC results.
Message 2570, level 16, status 3, line 1
 Page (1:20239), slot 6 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20241), slot 13 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20241), slot 20 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20241), slot 27 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20730), slot 19 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20730), slot 20 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20730), slot 27 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type is "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20730), slot 28 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type is "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20731), slot 26 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20755), slot 17 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
Message 2570, level 16, status 3, line 1
 Page (1:20861), slot 15 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.
The object'MyTable'has 21343 lines on page 771.
CHECKDB In the table'MyTable'(object ID 1371151930), 0 allocation errors and 11 consistency errors were found.
*/

Message 2570, level 16, status 3, line 1
Page (1:20239), slot 6 is located in object ID 1371151930, index ID 1, partition ID 72057594110345216, allocation unit ID 72057594130530304 (type "In-row data"). The value of column "NAME" is beyond the range of the data type "varchar". Please update this column to a valid value.


The current version of the SQL Server instance is Microsoft SQL Server 2008 R2 (RTM), while the database compatibility level is "SQL Server 2005 (90)". The database is migrated from the old instance, but not necessarily because of migration problems, but also because of operation data before or after migration.


The problem is that in earlier versions, invalid or out-of-range data may be stored in SQL Server databases.

In this case, the data page is not damaged, or you can view the data in the table, but the field value is beyond the storage scope of the data type.


Solution:

Look at the field type and find that the field "NAME" type is VARCHAR(20). Now let's look at the data beyond the scope.

View the data page type:

DBCC TRACEON(3604,1)
DBCC PAGE ([MyDB] ,1,20239,3 )

........................

ID = 5351  

Slot 0 Column 2 Offset 0xc2 Length 6 Length (physical) 6

........................


Because of the clustered index of ID, the query finds out the maximum and minimum ID of the data page, looks at the record of the query table, and converts it to the field type for correction.

SELECT NAME,convert(varchar(20),NAME) FROM MyTable WITH(NOLOCK) WHERE ID BETWEEN 5351 AND 5379


As you can see, some field values appear a question mark (unknown character), and the conversion type is corrected to normal, which may be the case when Unicode is inserted into the general varchar type. Errors like this may also occur when values such as [-0.00] are stored in fields of positive type, i.e., illegal values appear.

Therefore, as in the case above, the solution is to change the correct value:

UPDATE A SET NAME=convert(varchar(20),NAME) FROM MyTable A WHERE ID BETWEEN 5351 AND 5379
The table can be updated directly if there are fewer records.

UPDATE A SET NAME=convert(varchar(20),NAME) FROM MyTable A 
Check again after the update is completed:

DBCC CHECKTABLE (MyTable) WITH DATA_PURITY
--perhaps
DBCC CHECKDB(MyDB)

Repair completed, no errors!!

References:

Troubleshooting DBCC error 2570 in SQL Server 2005 and later versions

DBCC CHECKTABLE (Transact-SQL)


Posted by djheru on Sat, 29 Jun 2019 16:16:08 -0700