Skip to content

Commit 8b0c8b2

Browse files
committed
Add check for file shrinks
I lumped shrink file and shrink database in together
1 parent 987364e commit 8b0c8b2

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

sp_Blitz.sql

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,15 +3845,15 @@ IF @ProductVersionMajor >= 10
38453845
NULLIF(
38463846
CHARINDEX('(', CONVERT(NVARCHAR(MAX), t.TextData)),
38473847
0),
3848-
LEN(CONVERT(NVARCHAR(MAX), t.TextData)) + 1 ))
3848+
LEN(CONVERT(NVARCHAR(MAX), t.TextData)) + 1 )) --This replaces everything up to an open paren, if one exists.
38493849
, SUBSTRING(CONVERT(NVARCHAR(MAX), t.TextData),
38503850
ISNULL(
38513851
NULLIF(
38523852
CHARINDEX(' WITH ',CONVERT(NVARCHAR(MAX), t.TextData))
38533853
, 0),
38543854
LEN(CONVERT(NVARCHAR(MAX), t.TextData)) + 1),
38553855
LEN(CONVERT(NVARCHAR(MAX), t.TextData)) + 1 )
3856-
, '')
3856+
, '') --This replaces any optional WITH clause to a DBCC command, like tableresults.
38573857
) AS [dbcc_event_trunc_upper],
38583858
UPPER(
38593859
REPLACE(
@@ -4017,6 +4017,33 @@ IF @ProductVersionMajor >= 10
40174017

40184018
END
40194019

4020+
IF NOT EXISTS ( SELECT 1
4021+
FROM #SkipChecks
4022+
WHERE DatabaseName IS NULL AND CheckID = 204 )
4023+
BEGIN
4024+
INSERT INTO [#BlitzResults]
4025+
( [CheckID] ,
4026+
[Priority] ,
4027+
[FindingsGroup] ,
4028+
[Finding] ,
4029+
[URL] ,
4030+
[Details] )
4031+
4032+
SELECT 204 AS CheckID ,
4033+
50 AS Priority ,
4034+
'DBCC Events' AS FindingsGroup ,
4035+
'DBCC SHRINK%' AS Finding ,
4036+
'' AS URL ,
4037+
'The user ' + COALESCE(d.nt_user_name, d.login_name) + ' has run file shrinks ' + CAST(COUNT(*) AS NVARCHAR(100)) + ' times between ' + CONVERT(NVARCHAR(30), MIN(d.min_start_time)) + ' and ' + CONVERT(NVARCHAR(30), MAX(d.max_start_time)) +
4038+
'. So, uh, are they trying to fix corruption, or cause corruption?'
4039+
AS Details
4040+
FROM #dbcc_events_from_trace d
4041+
WHERE d.dbcc_event_trunc_upper LIKE N'DBCC SHRINK%'
4042+
GROUP BY COALESCE(d.nt_user_name, d.login_name)
4043+
HAVING COUNT(*) > 0
4044+
4045+
END
4046+
40204047

40214048
/*End: checking default trace for odd DBCC activity*/
40224049

0 commit comments

Comments
 (0)