31

Is it possible to enable or disable the sql server agent using t-sql?

Jill
  • 473
  • 3
  • 7
  • 15

2 Answers2

48
exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 0 --Disable
exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 1 --Enable
Russell Fox
  • 5,273
  • 1
  • 24
  • 28
7

You can use this to set it ON or OFF

   EXEC xp_servicecontrol N'stop',N'SQLServerAGENT'
   EXEC xp_servicecontrol N'start',N'SQLServerAGENT'