For many of my customers I’ve got them setup to use maintenance plans because they are small shops without a DBA and the maintenance plans give them something visual which they can easily tweak later on if needed without having to have me come in to make a small change to their reindexing or backups, etc.

One of the big failings of the maintenance plans is the reporting in Management Studio. If you right click on a maintenance plan you get an option to view reports and it gives you a whole bunch of really nice info … sometimes. After the plan has been running for a while it just sits there not giving you any useful information. And that’s because the code behind the maintenance plan report page … SUCKS!

The process does a bunch of row by row querying instead of just dumping a single large recordset like any normal application. So how do you get that useful information from SQL Server. The query below will give you the exact same information that the GUI gives you, but without waiting forever for the GUI to open up. Just change the plan and subplan names to the ones that you are looking for and run the query.

SELECT
ld.line1 AS [Line1],
ld.line2 AS [Line2],
ld.line3 AS [Line3],
ld.line4 AS [Line4],
ld.line5 AS [Line5],
ld.server_name AS [ServerName],
ld.start_time AS [StartTime],
ld.end_time AS [EndTime],
ld.error_number AS [ErrorNo],
ld.error_message AS [ErrorMessage],
ld.command AS [Command],
ld.succeeded AS [Succeeded]
FROM
msdb.dbo.sysmaintplan_plans AS s
INNER JOIN msdb.dbo.sysmaintplan_subplans AS sp ON sp.plan_id=s.id
INNER JOIN msdb.dbo.sysmaintplan_log AS spl ON spl.subplan_id=sp.subplan_id
INNER JOIN msdb.dbo.sysmaintplan_logdetail AS ld ON ld.task_detail_id=spl.task_detail_id
WHERE
((sp.subplan_name= ‘Full’)and((s.name=’Backups’)))
ORDER BY
[StartTime] DESC

Denny

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?

Share via
Copy link
Powered by Social Snap