{"id":360,"date":"2014-05-20T16:09:56","date_gmt":"2014-05-20T22:09:56","guid":{"rendered":"https:\/\/jackdonnell.com\/?p=360"},"modified":"2015-12-27T22:27:49","modified_gmt":"2015-12-28T04:27:49","slug":"script-commands-to-disableenable-sql-agent-jobs","status":"publish","type":"post","link":"https:\/\/jackdonnell.com\/?p=360","title":{"rendered":"Script Commands to Disable\/Enable SQL Agent Jobs"},"content":{"rendered":"<p>The script below is a quick way to create disable and enable SQL Agent job commands for existing jobs. It will script out the correct &#8216;EXEC msdb..sp_update_job&#8217; statements. In this example, the where clause filters for &#8220;enabled = 1&#8221;, but you can use it create statements based of various job characteristics. We tend to use these when migrating to new servers and want to leave the old server in place. <\/p>\n<pre lang=\"tsql\" line=\"1\" escaped=\"true\">\/*\r\nScript commands to disable\/enable jobs\r\n5\/20\/2014 JCD\r\nTested: 2005, 2008 R2 and 2012 SP1\r\n\r\nYou can further filter jobs with other sysjobs columns to specify\r\nan even smaller subset of enabled jobs. Good examples for adding\r\nfilers are owner_sid, description and category_id.\r\n\r\n*\/\r\nSET NOCOUNT ON\r\nGO\r\n\r\nUSE msdb\r\nGO\r\n-- Script disable commands for enabled jobs\r\nSELECT 'EXEC msdb..sp_update_job @job_name='''+REPLACE(name,'''','''''')+''',@enabled=0;'\r\nFROM msdb..sysjobs\r\nWHERE enabled = 1;\r\nGO\r\n-- Script enable commands to enabled jobs after disabling. Should be run when creating the disable script\r\nSELECT 'EXEC msdb..sp_update_job @job_name='''+REPLACE(name,'''','''''')+''',@enabled=1;'\r\nFROM msdb..sysjobs\r\nWHERE enabled = 1;\r\nGO\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Quick way to script disable and enable SQL Agent jobs.<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/jackdonnell.com\/?p=360\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[273,266,5],"tags":[303,324,323,325,315,249,35,36,288,295,52,322,291],"class_list":["post-360","post","type-post","status-publish","format-standard","hentry","category-administration","category-dba","category-t-sql","tag-dba","tag-disable","tag-enable","tag-jobs","tag-query","tag-script","tag-select","tag-sql","tag-sql-agent","tag-sql-server","tag-ssms","tag-sys-jobs","tag-t-sql"],"_links":{"self":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=360"}],"version-history":[{"count":6,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}