How to get `dbcc checkdb` report when run via agent job?



  • When I run dbcc checkdb via management studio, then I get the full report as output.

    However when I run dbcc checkdb via sql agent job, then I think that the job status will either show as success if the dbcc checkdb detects no errors; else job status will show as failure. Is that correct?

    How do I get the report when dbcc checkdb is run via sql agent job?



  • You want the output from the DBCC CHECKDB command how?

    1. In the job history (sysjobhistory in msdb) as you can open in SSMS?
    2. As a text file?
    3. Included in an email sent to you?

    For 1, this is already done for you, there's nothing extra you have to do. Make sure that you in the GUI select that job step, not the whole job when you look at job history. This is limited to approx. 4000 characters.

    For 2, if you want as a file, then just configure an output file for that job step. You won't get to this file from SSMS, so make sure you configure that file to a good place.

    For 3, if you want in an email, then there's no built-in support for this in MSSQL. You can create an output file and then use sp_send_dbmail and attach that output file in the email. I've written a stored procedure that facilitates this, which you can find https://karaszi.com/mailafterjob-send-email-after-agent-job-include-ouput-files .




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2