While I was about to leave from office, I received a mail from one of our customer to change the Job Owner details for 20 different jobs in four different instances. Although I prefer to use the GUI, but this time I prefer to use t-sql script to complete the assigned task because I don’t want to click the mouse buttons so many times. 😉
With a little search on Books Online, I found the script which I was looking for. There is a system stored procedure, sp_update_job, which does the exact thing, what I was looking for. The first required parameter for this stored procedure is either the Job ID or the Job Name. A lot of different attributes of a job can be modified by using the above stored procedure. As I had to modify the Job Owner Details, I used the following piece of code:
EXEC msdb.dbo.sp_update_job @job_name = 'Testjob 12', @owner_login_name = 'skg\skganguly';
For a complete list of attributes supported by this stored procedure, refer this article. With this SP, I was able to complete the task within 10 minutes. I found this script very helpful, so thought of documenting it. Hope, you will find it useful.