{"id":1279,"date":"2016-09-30T23:32:24","date_gmt":"2016-09-30T23:32:24","guid":{"rendered":"http:\/\/www.theSQLReport.com\/?p=1279"},"modified":"2016-10-12T12:12:02","modified_gmt":"2016-10-12T12:12:02","slug":"email-the-results-of-dbcc-checkdb","status":"publish","type":"post","link":"https:\/\/www.theSQLReport.com\/?p=1279","title":{"rendered":"Email the results of DBCC CHECKDB"},"content":{"rendered":"<h3>Situation:<\/h3>\n<p>We had a very busy SQL Server, that could not have &#8220;DBCC CHECKDB&#8221; run during business hours with out impacting others.\u00a0 I was being asking for the output from the &#8220;DBCC CHECKDB&#8221; job.\u00a0 What I wanted was a nice script that would run in the middle of the night, and e-mail the output from the &#8220;DBCC CHECKDB&#8221;, so that I could forward the output file as an email attachment.<\/p>\n<h3>Resolution:<\/h3>\n<p>I inserted the following sql script in a SQL Agent job &amp; scheduled the job to run in the middle of the night:<\/p>\n<pre id=\"yui_3_16_0_ym19_1_1475277292801_2890\" class=\"yiv3359210469MsoNormal\"><span id=\"yui_3_16_0_ym19_1_1475277292801_2889\"><\/span>EXECUTE msdb.dbo.sp_send_dbmail\r\n@profile_name = 'DBA',\r\n@recipients = 'myemail@mycompany.com;',\r\n@Subject = 'My SQL Server DBCC CHECKDB Results',\r\n@query = N'USE MyBusyDB; DBCC CHECKDB;',\r\n@attach_query_result_as_file = 1,\r\n@query_attachment_filename = 'CheckDBOutput.txt'\r\nGO<\/pre>\n<div id=\"attachment_1286\" style=\"width: 716px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2016\/09\/EmailCheckDB.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1286\" class=\"wp-image-1286 size-full\" src=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2016\/09\/EmailCheckDB.jpg\" alt=\"Emailed DBCC CHECKDB Output\" width=\"706\" height=\"194\" srcset=\"http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2016\/09\/EmailCheckDB.jpg 706w, http:\/\/www.theSQLReport.com\/wp-content\/uploads\/2016\/09\/EmailCheckDB-300x82.jpg 300w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/a><p id=\"caption-attachment-1286\" class=\"wp-caption-text\">Emailed DBCC CHECKDB Output<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Situation: We had a very busy SQL Server, that could not have &#8220;DBCC CHECKDB&#8221; run during business hours with out impacting others.\u00a0 I was being asking for the output from &hellip; <a class=\"readmore\" href=\"https:\/\/www.theSQLReport.com\/?p=1279\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1286,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[86,85],"class_list":["post-1279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql-server","tag-dbcc-checkdb","tag-sp_send_dbmail"],"_links":{"self":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1279"}],"collection":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1279"}],"version-history":[{"count":7,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1279\/revisions"}],"predecessor-version":[{"id":1289,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/posts\/1279\/revisions\/1289"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=\/wp\/v2\/media\/1286"}],"wp:attachment":[{"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theSQLReport.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}