SQL Server – DBCC Failed on Data Purity Check

Background

Reviewing SQL Server Agent Jobs and noticed that one of Database Maintenance Job was disabled.

Enabled and ran it, and it errored out.

 

Failed Job

Here is the failed Job…

StartJobs-20170303-0521PM (Cropped up)

 

SQL Dump

Unfortunately, not only did the job fail, it created SQL Dump files, as well.

Here is a sample of the created dump files.

Image

SQLDump0333_log_20170303_0526PM ( cropped-up)

 

Textual

 

 


2017-03-03 17:05:26.22 spid60      DBCC CHECKDB (SGS) WITH all_errormsgs, no_infomsgs, data_purity executed by LAB\dbsvc found 0 errors and repaired 0 errors. Elapsed time: 0 hours 0 minutes 1 seconds.  Internal database snapshot has split point LSN = 00013838:00000171:0001 and first LSN = 00013838:00000170:0001.
2017-03-03 17:07:08.99 spid60      DBCC CHECKDB (SRPA) WITH all_errormsgs, no_infomsgs, data_purity executed by LAB\dbsvc found 10 errors and repaired 0 errors. Elapsed time: 0 hours 1 minutes 42 seconds.  Internal database snapshot has split point LSN = 003029a5:0001b40e:0001 and first LSN = 003029a5:0001b40d:0001.
2017-03-03 17:07:09.14 spid60      Using 'dbghelp.dll' version '4.0.5'
2017-03-03 17:07:09.18 spid60      **Dump thread - spid = 0, EC = 0x0000000175F700F0
2017-03-03 17:07:09.19 spid60      ***Stack Dump being sent to E:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\LOG\SQLDump0329.txt
2017-03-03 17:07:09.20 spid60      * *******************************************************************************
2017-03-03 17:07:09.20 spid60      *
2017-03-03 17:07:09.20 spid60      * BEGIN STACK DUMP:
2017-03-03 17:07:09.20 spid60      *   03/03/17 17:07:09 spid 60
2017-03-03 17:07:09.20 spid60      *
2017-03-03 17:07:09.20 spid60      * DBCC database corruption
2017-03-03 17:07:09.20 spid60      *
2017-03-03 17:07:09.21 spid60      * Input Buffer 196 bytes -
2017-03-03 17:07:09.21 spid60      *             EXECUTE [dbo].[DatabaseIntegrityCheck] @Databases = 'USER_DAT
2017-03-03 17:07:09.21 spid60      *  ABASES', @LogToTable = 'Y'
2017-03-03 17:07:09.21 spid60      *  
2017-03-03 17:07:09.21 spid60      * *******************************************************************************
2017-03-03 17:07:09.21 spid60      * -------------------------------------------------------------------------------
2017-03-03 17:07:09.21 spid60      * Short Stack Dump
2017-03-03 17:07:09.38 spid60      Stack Signature for the dump is 0x00000000000000F4
2017-03-03 17:07:23.11 spid60      External dump process return code 0x20000001.
External dump process returned no errors.

2017-03-03 17:09:07.28 spid60      DBCC CHECKDB (SRPA_CORRUPT2) WITH all_errormsgs, no_infomsgs, data_purity executed by LAB\dbsvc found 10 errors and repaired 0 errors. Elapsed time: 0 hours 1 minutes 41 seconds.  Internal database snapshot has split point LSN = 00302996:0000d702:0001 and first LSN = 00302996:0000d701:0001.
2017-03-03 17:09:07.28 spid60      **Dump thread - spid = 0, EC = 0x0000000175F700F0
2017-03-03 17:09:07.28 spid60      ***Stack Dump being sent to E:\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\LOG\SQLDump0330.txt
2017-03-03 17:09:07.28 spid60      * *******************************************************************************
2017-03-03 17:09:07.28 spid60      *
2017-03-03 17:09:07.28 spid60      * BEGIN STACK DUMP:
2017-03-03 17:09:07.28 spid60      *   03/03/17 17:09:07 spid 60
2017-03-03 17:09:07.28 spid60      *
2017-03-03 17:09:07.28 spid60      * DBCC database corruption
2017-03-03 17:09:07.28 spid60      *
2017-03-03 17:09:07.28 spid60      * Input Buffer 196 bytes -
2017-03-03 17:09:07.28 spid60      *             EXECUTE [dbo].[DatabaseIntegrityCheck] @Databases = 'USER_DAT
2017-03-03 17:09:07.28 spid60      *  ABASES', @LogToTable = 'Y'
2017-03-03 17:09:07.28 spid60      *  
2017-03-03 17:09:07.28 spid60      * *******************************************************************************
2017-03-03 17:09:07.28 spid60      * -------------------------------------------------------------------------------
2017-03-03 17:09:07.28 spid60      * Short Stack Dump
2017-03-03 17:09:07.35 spid60      Stack Signature for the dump is 0x00000000000000F4 

 

 

 

Troubleshooting

Review Job

Reviewed the Job and it’s lone step.

 

Repair Database

Scripted out DBCC/Repair Rebuild

Outline

  1. Place database in single user mode
  2. Initiate new transaction
    • Issue DBCC with following options
      • Data purity check
      • Using Repair/Rebuild, attempt to repair errors
      • Display all error messages
      • Withhold informational messages
  3. Exit Database from single user mode

Script

 
use master;

ALTER DATABASE [HRDB]
	SET SINGLE_USER
		WITH ROLLBACK IMMEDIATE;
GO

set nocount on;
set XACT_ABORT on;

declare @dateBegin datetime
declare @dateDBCCCompleted datetime
declare @dateFullCompletion datetime

declare @strLog varchar(80)
declare @DATE_STYLE int

declare @NUMBER_OF_COLUMNS int
declare @CHAR_LINEBREAK varchar(600)

set @NUMBER_OF_COLUMNS = 120
set @DATE_STYLE = 100
set @CHAR_LINEBREAK = replicate('=', @NUMBER_OF_COLUMNS)

begin tran

	print @CHAR_LINEBREAK
	set @dateBegin = getdate()
	set @strLog = 'Date DBCC Began :- ' + convert(varchar(20), @dateBegin, @DATE_STYLE)
	print @strLog

	print @CHAR_LINEBREAK


		DBCC CHECKDB
		(
			  [HRDB]
		   ,  REPAIR_REBUILD 
		)
		with
			    ALL_ERRORMSGS 
			  , no_infomsgs
			  , data_purity


	print @CHAR_LINEBREAK

	set @dateDBCCCompleted = getdate()
	set @strLog = 'Date DBCC Completed :- ' + convert(varchar(20), @dateDBCCCompleted, @DATE_STYLE)
	print @strLog

	print @CHAR_LINEBREAK

rollback tran

	set @dateFullCompletion = getdate()
	set @strLog = 'Date Full Completion :- ' + convert(varchar(20), @dateFullCompletion, @DATE_STYLE)
	print @strLog

	print @CHAR_LINEBREAK

go

ALTER DATABASE [HRDB]
	SET MULTI_USER
		WITH ROLLBACK IMMEDIATE;
GO


 

 

Output

Image

DBCCCheckDB_ProcessLog_20170303_0559PM

 

Textual

 
========================================================================================================================
Date DBCC Began :- Mar 3 2017 5:56PM
========================================================================================================================
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 12 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 13 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 14 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 59 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 60 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 61 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 62 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1237088), slot 63 in object ID 1549248574, index ID 1, partition ID 72057616969498624, alloc unit ID 72057616977821696 (type "In-row data"). Column "Holding" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
CHECKDB found 0 allocation errors and 8 consistency errors in table 'usr_Portfolio_Dirty_Data' (object ID 1549248574).
Msg 2570, Level 16, State 3, Line 35
Page (1:1781040), slot 0 in object ID 1585141138, index ID 1, partition ID 72057616957440000, alloc unit ID 72057616965697536 (type "In-row data"). Column "Value" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
Msg 2570, Level 16, State 3, Line 35
Page (1:1781040), slot 1 in object ID 1585141138, index ID 1, partition ID 72057616957440000, alloc unit ID 72057616965697536 (type "In-row data"). Column "Value" value is out of range for data type "real". Update column to a legal value.
The system cannot self repair this error.
CHECKDB found 0 allocation errors and 2 consistency errors in table 'mkt_FactorData13' (object ID 1585141138).
CHECKDB found 0 allocation errors and 10 consistency errors in database 'HRDB'.
========================================================================================================================
Date DBCC Completed :- Mar 3 2017 5:58PM
========================================================================================================================
Date Full Completion :- Mar 3 2017 5:58PM
========================================================================================================================
 

 

 

Explanation

  • Two tables and columns combination cited
    • Table :- usr_Portfolio_Dirty_Data, Column :- Holding
    • Table :- mkt_FactorData13, Column :- Value
  • All cited columns are defined as having the real datatype
  • Message reads
    • Column “Holding” value is out of range for data type “real”.  Update column to a legal value.
      The system cannot self repair this error.
    • Column “Value” value is out of range for data type “real”.  Update column to a legal value.
      The system cannot self repair this error.

 

 

Data Purity Check

The data purity check cited that some values are not legal.

The data type for the columns cited is real.

 

Validation

 

[constant].[numberMax]

Code


use [master]
go

if schema_id('CONSTANT') is null
begin

	exec('create schema [CONSTANT] authorization [dbo]')

end
go

if object_id('[constant].[numberMax]') is null
begin

	exec('create view [constant].[numberMax] as select [shell] = 1/0 ')

end
go

alter view [constant].[numberMax] 
with schemabinding
as 
	select 

		/*
			real
				a) - 3.40E + 38 to -1.18E - 38
				b) 0 
				c) 1.18E - 38 to 3.40E + 38	
				
				Size
					:- 4 Bytes

		*/
		  [realNumber1Low] 
			= cast(-3.40E+38 as real)
		
		, [realNumber1High] 
			= cast(-1.18E-38 as real)

		, [realNumber2Low] 
			= cast(1.18E-38 as real)

		, [realNumber2High] 
			= cast(3.40E+38 as real)

go

grant select on [constant].[numberMax] to [public]
go

[dbo].[fn_DecimalPlaces]

Code


use master
go

IF NOT EXISTS 
(
	SELECT * 
	FROM   sys.objects tblSO
	WHERE  tblSO.object_id = object_id('[dbo].[fn_DecimalPlaces]')

)
begin

	exec('create function [dbo].[fn_DecimalPlaces]() returns tinyint as begin return (-1) end ');

end

GO

ALTER FUNCTION [dbo].[fn_DecimalPlaces]
(
	@A float
)
RETURNS int
with schemabinding
AS
BEGIN

	/*
		Topic  :- Count Decimal Places
		Author :- Sergiy
		URL    :- https://www.sqlservercentral.com/Forums/Topic314390-8-1.aspx
	*/
	declare @R int

	IF ( @A IS NULL )
	begin

		RETURN NULL

	end


	set @R = 0

	while @A - str(@A, 18 + @R, @r) <> 0
	begin 

		SET @R = @R + 1

	end

	RETURN @R

END
GO

grant execute on [dbo].[fn_DecimalPlaces] to public
go


 

dbo.Holding

Code



SELECT
		top 15
		  [Holding]
		--, [HoldingTryParse] = TRY_PARSE([Holding] as real) 
		, [HoldingAsFloat] = cast([Holding] as float)
		, [Length] = len([Holding])
		, [NumberofDecimalPlaces]
			= dbo.fn_DecimalPlaces([Holding])

from   [dbo].[usr_Portfolio_Dirty_Data] tblPDD

cross apply [constant].[numberMax] vwCNM

where  (

			  ( [Holding] <> 0.0 )

		/*
			AND 
				(
					    ( [Holding] < CONVERT(real,1.18E-38) OR [Holding] > CONVERT(real,3.40E+38) ) 
					AND ( [Holding] < CONVERT(real,-3.40E+38) OR [Holding] > CONVERT(real,-1.18E-38) )
				)

		*/

			AND 
				(
					(
							  ( [Holding] < [realNumber2Low] ) OR ( [Holding] >  [realNumber2High] )

					)

					AND
					(
							  ( [Holding] < [realNumber1Low] ) OR ( [Holding] >  [realNumber1High] )

					)

				)

	)		



Output

validatedata_holding_20170304_1201m

dbo.mkt_FactorData13

Code

 

 
SELECT  top 5 
		  [WSCode]
		, [DataDate]
		, [Value]
		--, [ValueTryParse] = TRY_PARSE([Value] as real) 
		, [ValueAsFloat] = cast([Value] as float)
		, [ValueIsNumeric] = IsNumeric([Value])
		, [Length] = len([Value])
		, [NumberofDecimalPlaces]
			= [master].dbo.fn_DecimalPlaces([Value])

from   [dbo].[mkt_FactorData13] tblMKT

cross apply [constant].[numberMax] vwCNM

where  (

			  ( [Value] <> 0.0 )
			
			/*
				WHERE col2<>0.0 
				AND (col2 < CONVERT(real,1.18E-38) OR col2 > CONVERT(real,3.40E+38)) 
				AND (col2 < CONVERT(real,-3.40E+38) OR col2 > CONVERT(real,-1.18E-38)) 
			*/

			/*
			AND 
				(
					    ( [Value] < CONVERT(real,1.18E-38) OR [Value] > CONVERT(real,3.40E+38) ) 
					AND ( [Value] < CONVERT(real,-3.40E+38) OR [Value] > CONVERT(real,-1.18E-38) )
				)

			*/

			AND 
				(
					(
							  ( [Value] < [realNumber2Low] ) OR ( [Value] >  [realNumber2High] )

					)

					AND
					(
							  ( [Value] < [realNumber1Low] ) OR ( [Value] >  [realNumber1High] )

					)

				)
	)		



 

 

Output

validatedata_marketing_20170304_1155am

Workarounds

Outline

There are a couple of workarounds

  1. Skip puritch check
  2. Change column datatype from real to float, currency if it is a currency field

Skip Purity Check

Ola Hallengren

Original


sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d AdminDB -Q "EXECUTE [dbo].[DatabaseIntegrityCheck] @Databases = 'USER_DATABASES', @LogToTable = 'Y' " -b

Revision


sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d AdminDB -Q "EXECUTE [dbo].[DatabaseIntegrityCheck] @Databases = 'USER_DATABASES', @LogToTable = 'Y', @PhysicalOnly = 'Y'  " -b

Explanation

  1. Add @PhysicalOnly=Y

Connect

Opened up a Connect Item.

  1. DBCC CHECKDB/show Purity cites data type of float as incorrect even while correct – by Daniel Adeniji
    Item Number: – 3126630
    Link :- Link
    Type :- Bug
    Status :- Active
    Date Opened :- 3/5/2017 2:32:29 PM

GitHub

Uploaded files to GitHub.
Link is here

 

Summary

It seems that on this particular version of SQL Server, SQL sometimes has problems running purity checks against certain records.

The failing column are defined as having the float datatype.

BTW, the version# is

SQL Server Version :- Microsoft SQL Server 2008 R2 (SP3) – 10.50.6000.34 (X64)
Aug 19 2014 12:21:34
Copyright (c) Microsoft Corporation
Enterprise
Product Level :- SP3
Product Version :- 10.50.6000.34
Edition :- Enterprise Edition (64-bit)

References

  1. DBCC CheckDB
    • Developer Network
    • Support.microsoft.com
      • Troubleshooting DBCC error 2570 in SQL Server 2005 and later versions
        Link
    • Sergessqlnotes’s Blog
      • DBCC CHECKDB Msg 2570 Data Purity Errors
        Link
  2. DataType
    • Developer Network
      • Transact-SQL Reference (Database Engine) Data Types (Transact-SQL)  Numeric Types
        • float and real (Transact-SQL)
          Link
    • Tech Republic
      • 10+ common questions about SQL Server data types
        Link
  3. Microsoft Developer
    • SQL with Manoj
      • Use new TRY_PARSE() instead of ISNUMERIC() | SQL Server 2012
        Link

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s