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
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1493 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 Guru
SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)

Group: General Forum Members
Points: 153714 Visits: 9672
exec msdb..sp_update_job @job_id = 0xC0923E436928064EA33B46B2A47BFF61 , @enabled = 0
Paul Paiva
Paul Paiva
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

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

- Paul

http://paulpaivasql.blogspot.com/
Paul G Olecki
Paul G Olecki
SSC-Enthusiastic
SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)

Group: General Forum Members
Points: 193 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 Guru
SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)

Group: General Forum Members
Points: 153714 Visits: 9672
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-Enthusiastic
SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)

Group: General Forum Members
Points: 193 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 Guru
SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)SSC Guru (153K reputation)

Group: General Forum Members
Points: 153714 Visits: 9672
Ya that's quite a few .
Anchelin
Anchelin
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1309 Visits: 1195
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-Enthusiastic
SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)SSC-Enthusiastic (193 reputation)

Group: General Forum Members
Points: 193 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
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1309 Visits: 1195
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