change owner or multiple jobs

  • Hi,

    how can i change owner to differenet user for all 200 jobs running on SQL2005 ?

    thanks

    Pat

  • declare @jb_name nvarchar(128)

    declare c cursor fast_forward for

    select name from msdb.dbo.sysjobs

    open c

    fetch next from c into @jb_name

    while @@fetch_status = 0

    begin

    print 'changing : ' + @jb_name + ' ...'

    exec msdb.dbo.sp_update_job @job_name = @jb_name, @owner_login_name=N'sa'

    fetch next from c into @jb_name

    end

    close c

    deallocate c


    * Noel

  • Looks good to me!

    Be aware that I've seen in SS2K jobs change to a new owner if they're edited, so keep this around. Not sure if that's a problem in SS2K5, but you might need to watch for that.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply