DBCC CHECKDB Results to Table
This problem was driving me nuts. Finally I found an old post from 2004 that gave me just enough information to make a go of it with SQL Server 2005. I also modified the code to not include creating a procedure just to run the DBCC command. I like my method better.
I will be updating this post shortly as the table definition is not quite correct. I need to get a test SQL box up so I can fine tune the table definition.
/* This script will run the command DBCC CHECKDB ('Master') */
/* and store the results in a temp table. */
/* If errors are found, the Level will be > 10 */
/* NOTE: This is not documented, which probably means */
/* "Not Supported" */
/* It has been tested for SQL Server 2005 only. */
CREATE TABLE #Temp (
Error INT,
Level INT,
State INT,
MessageText VARCHAR(7000),
RepairLevel INT,
Status INT,
DbId INT,
Id INT,
IndId INT,
[File] INT,
Page INT,
Slot INT,
RefFile INT,
RefPage INT,
RefSlot INT,
Allocation INT )
INSERT INTO #Temp
EXEC ('DBCC CHECKDB (TableName) WITH TABLERESULTS')
SELECT MessageText FROM #Temp
DROP TABLE #Temp
Labels: CHECKDB, DBA, DBCC, SQL Server 2005, TSQL
