Sql-server – Maintenance Job Failing

maintenance-planssql server

I didn't realize but it appears you can put switches on your job to run a maintenance plan. Am I correct on that?

We have 3 jobs that are running the same maintenance plan but doing different things with it.

The first two jobs succeed, and the 3rd job fails. Here are the jobs .I cannot figure out why that 3rd job fails. I was able to find a table in msdb that shows that plan ID, and all three of these jobs have the same plan id, so I know it uses the same maintenance plan.

    The code for the three of them are:

    EXECUTE master.dbo.xp_sqlmaint N'-PlanID 5E6B7EDB-56E5-4EAD-81E6-BDFD1514F9DD  -RebldIdx 100 '
    EXECUTE master.dbo.xp_sqlmaint N'-PlanID 5E6B7EDB-56E5-4EAD-81E6-BDFD1514F9DD  -VrfyBackup -BkUpMedia DISK -BkUpDB "F:\Backup" -DelBkUps 1DAYS -BkExt "BAK"'
    EXECUTE master.dbo.xp_sqlmaint N'-PlanID 5E6B7EDB-56E5-4EAD-81E6-BDFD1514F9DD  -CkDBRepair  '

The first two pass, and the 3rd one is the one that fails…

Best Answer

One thing to note is that xp_sqlmaint is scheduled to removed in the future and is not the recommended method for running the maintenance plans. (Though it is still supported at this time.)

For SQL Server maintenance I would recommend downloading the Ola Hallengren solution at https://ola.hallengren.com/. This is a freely provided product for managing the integrity checks as well as, if you wish, to automate your database backups. And Ola is quick to respond with personal help.

These are highly respected scripts, which I have been using for several years.

You seem to have a corruption problem if the -CkDBRepair cannot finish the check. If that is the case, then you will need to be careful in how you fix the problem so as to avoid as much loss as possible. So please carefully read:

DBCC CHECKDB (Transact-SQL)

Be sure to read the warnings on DBCC CHECKDB and the impact of allowing data loss when resolving the problem.