Wednesday, December 31, 2014

Update SQL Agent jobs to a new job owner

Good Bye... 2014


I dedicated all my 2014 work and script to my little brother, Aung Phyo Tha, who suffers from brain aneurysm and is still unconscious for 46 Days. Please pray for him to wake up very soon. Thank you.

The following script is to update all sql agent jobs to a new owner. I have tested the script and it worked. Please run it in Development first. Enjoy Scripting.....

Declare @Job_ID uniqueidentifier
Declare @sql nvarchar(4000)
Declare @NewJobowner varchar(10)

Set @NewJobowner = 'Domain\newowner'

Declare Job_Csr cursor Local for

select job_id from msdb..sysjobs_view
where enabled = 1

Open Job_Csr;
Fetch Job_Csr into

@job_ID

While @@FETCH_STATUS = 0

Begin


Exec msdb.dbo.sp_update_job @job_id = @job_Id,
@owner_login_name = @Newjobowner


Fetch Job_Csr into
@Job_ID

End

Close Job_Csr
Deallocate Job_Csr

2 comments:

  1. Truly sorry to hear about your little brother. I hope he recovers and gets well soon. I will keep him in my thoughts and prayers. Thank you for being a truly kind and sharing person. I wish you and family good health and good fortune for 2015. -Tony

    ReplyDelete

How to add a Database to AlwaysOn Availability Group with four different options

To add a database to an existing AlwaysOn availability group, MS has given us four options to choose from Automatic seeding Full database an...