SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How can I disable a Job via TSQL


How can I disable a Job via TSQL

Author
Message
Paul Paiva
Paul Paiva
SSC Eights!
SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)

Group: General Forum Members
Points: 811 Visits: 265

I want to do an upgrade on a busy SQL 2000 server that has lots of jobs kicking off at different times. But first I need to wait until there are no jobs running before I shut down the SQL Agent.

My plan was to make a copy of sysjobs, then I did

UPDATE sysjobs SET Enabled = 0

To my surprise the jobs kept executing. When I queried the table, sure enough the Enabled column (smallint) was all zeros. I'm thinking the Agent must have a cache somewhere which needs to be refreshed, but I don't know how to do that.

Any ideas on how to disable my jobs via TSQL?

Thanks

Paul



- Paul

http://paulpaivasql.blogspot.com/
Ninja's_RGR'us
Ninja's_RGR'us
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30007 Visits: 9671
exec msdb..sp_update_job @job_id = 0xC0923E436928064EA33B46B2A47BFF61 , @enabled = 0
Paul Paiva
Paul Paiva
SSC Eights!
SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)SSC Eights! (811 reputation)

Group: General Forum Members
Points: 811 Visits: 265
Awesome, thanks very much.

- Paul

http://paulpaivasql.blogspot.com/
Paul G Olecki
Paul G Olecki
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 6

It might be easier to use:

exec msdb..sp_update_job @job_name = 'Job Name', @enabled = 0

Paul (polecki@Insurance.com)


Ninja's_RGR'us
Ninja's_RGR'us
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30007 Visits: 9671
Good point... I used the profiler to find out what sql enterprise manager was generating to disable the job. But using the jobname is certainly much simpler.
Paul G Olecki
Paul G Olecki
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 6

The way I learned some of the s/p's was to right click on the job and choose All tasks...Generate SQL script. That shows many s/p's used to create a job on another server.


Ninja's_RGR'us
Ninja's_RGR'us
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30007 Visits: 9671
Ya that's quite a few .
Anchelin
Anchelin
SSC Veteran
SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)

Group: General Forum Members
Points: 251 Visits: 1128
Hi All

This is all well, but isnt there a script that loops through all the jobs and disable them all at once.

Thanks in advance
Paul G Olecki
Paul G Olecki
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 6
Depending on why you want to turn off all jobs, we usually just stop Sql Server Agent. We would do this if the source server was going to be down.

When we are ready to resume the jobs, we start it back up. Then we might have to manually run any jobs which needed to run during the outage.
Anchelin
Anchelin
SSC Veteran
SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)SSC Veteran (251 reputation)

Group: General Forum Members
Points: 251 Visits: 1128
Thanks for your reply Paul
Its a 3 phase plan we are going through.1)First put db in single-user mode.2)Then switch off the system and 3)then decomission the system.
We cant disable SQL Agent, we still need to backup the system dbs.

Thanks and Regards
A
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search