Home > Uncategorized > Code to Check DBCC CHECKDB DATA_PURITY Settings Through CMS

Code to Check DBCC CHECKDB DATA_PURITY Settings Through CMS

In this recent post, Paul Randal identified a bug in SQL Server versions 2005 and newer that prevents DBCC CHECKDB from running data purity checks against the master and model databases. Paul provides code to identify and fix the issue. The code below can be run through CMS to check the settings for master and model databases throughout your environment.

Many thanks to Paul for sharing this information.

--Declare local variable
DECLARE @sqlstr VARCHAR(2000)

--Create temp table
CREATE TABLE #dbccinfo
(ParentObject VARCHAR(256)
,Object VARCHAR(256)
,field SYSNAME
,value VARCHAR(256))

--Build @sqlstr variable to exec DBCC INFO for the master database
--Use the WITH TABLERESULTS parm to return results in a tabular format
SET @sqlstr = 'DBCC DBINFO (N''master'') WITH TABLERESULTS'

--Execute the @sqlstr, inserting the results into the temp table
INSERT INTO #dbccinfo
EXEC(@sqlstr)

--Build @sqlstr variable to exec DBCC INFO for the model database
--Use the WITH TABLERESULTS parm to return results in a tabular format
SET @sqlstr = 'DBCC DBINFO (N''model'') WITH TABLERESULTS'

--Execute the @sqlstr, inserting the results into the temp table
INSERT INTO #dbccinfo
EXEC(@sqlstr)

SELECT * FROM #dbccinfo

--Select the field and value from the temp table for the dbi_dbid parm 
--and the database id
SELECT field, value FROM #dbccinfo
WHERE field IN ('dbi_dbccFlags', 'dbi_dbid')

DROP TABLE #dbccinfo
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

%d bloggers like this: