Is it possible to enable or disable the sql server agent using t-sql?
Asked
Active
Viewed 3.7k times
2 Answers
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
-
1Thanks! is there a way to enable/disable the agent itself too? – Jill Apr 19 '12 at 18:16
-
2You're welcome! And yes, google xp_servicecontrol (I've never use it). – Russell Fox Apr 19 '12 at 18:23
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'

Jean-Philippe Vankemmel
- 1,134
- 10
- 4