Many SQL Server DBAs manage jobs through the SSMS GUI and do not know about the underlying T-SQL scripts being run. This blog shows how to use T-SQL to change the job owner for all the jobs owned by a specific login.
Suppose you have a SQL instance with hundred of jobs owned by a specific login [MyDomainRam]. The user left the organization, and his AD id is deactivated. You start getting job failure notification- The job failed. The owner (MyDomain Ram) of job TestJob does not have server access.
Can we change the job owners in one go? Yes, it is possible using the sp_manage_jobs_by_login stored procedure.
The following query updates the SQL Server agent job owners from ‘MyDoaminRam’ to SA account.
USE msdb ;
@action = N'REASSIGN',
@current_owner_login_name = N'MyDomainRam',
@new_owner_login_name = N'SA';
Using the following query, you can get a list of jobs with their name, owners, and status (enableddisbled).
SELECT s.name AS JobName, l.name AS JobOwner, enabled
FROM msdb..sysjobs s
LEFT JOIN master.sys.syslogins l ON s.owner_sid = l.sid
ORDER by l.name