-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path9-DBCC Last Run Report
63 lines (44 loc) · 1.29 KB
/
9-DBCC Last Run Report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--TSQL Script to know last DBCC Check run for all databases
CREATE TABLE #DBInfoResults
(
[ParentObject] VARCHAR(512),
[Object] VARCHAR(512),
[Field] VARCHAR(512),
[VALUE] VARCHAR(512)
)
CREATE TABLE #FindDBCCLastKnownGoodDate
(
[DatabaseName] SYSNAME,
[LastKnowGoodDBCCCheckDate] NVARCHAR(512),
)
DECLARE
@DatabaseName SYSNAME,
@ExecTSQL VARCHAR(512);
DECLARE cDBInfoResults CURSOR FOR
SELECT NAME
FROM sys.databases
WHERE STATE_DESC = 'ONLINE'
OPEN cDBInfoResults;
FETCH NEXT FROM cDBInfoResults INTO @DatabaseName;
WHILE @@Fetch_Status = 0
BEGIN
SET @ExecTSQL = 'Use [' + @DatabaseName +'];' + CHAR(10)+ CHAR(13) +
'DBCC DBInfo() WITH TABLERESULTS, NO_INFOMSGS;' + CHAR(10)+ CHAR(13)
INSERT INTO #DBInfoResults
EXECUTE (@ExecTSQL);
INSERT INTO #FindDBCCLastKnownGoodDate
(DatabaseName, [LastKnowGoodDBCCCheckDate])
SELECT @DatabaseName, VALUE
FROM #DBInfoResults where Field = 'dbi_dbccLastKnownGood'
TRUNCATE TABLE #DBInfoResults;
FETCH NEXT FROM cDBInfoResults INTO @DatabaseName;
END
CLOSE cDBInfoResults;
DEALLOCATE cDBInfoResults;
SELECT
DISTINCT([DatabaseName]) AS [Database Name]
,[LastKnowGoodDBCCCheckDate] AS [Last Know Good DBCC Check Date]
FROM #FindDBCCLastKnownGoodDate
ORDER BY [LastKnowGoodDBCCCheckDate] DESC
DROP TABLE #DBInfoResults
DROP TABLE #FindDBCCLastKnownGoodDate