This is a very handy piece of code that I have readily available. It is useful to use on servers that have dozens of SQL Agent jobs to find out who owns a job and whether it is enabled.
By default when someone creates a job it sets their name as the owner which means if their account becomes disabled, they have left the company for instance, the job will no longer work. I've seen exactly this issue many times over the years. So every now and again I will run this piece of code to find who the owner is and then ask them to assign it to a more suitable account.
By default when someone creates a job it sets their name as the owner which means if their account becomes disabled, they have left the company for instance, the job will no longer work. I've seen exactly this issue many times over the years. So every now and again I will run this piece of code to find who the owner is and then ask them to assign it to a more suitable account.
USE MSDB;
GO
SELECT j.NAME AS JobName
,u.NAME AS JobOwner
,j.enabled
FROM sysjobs j
LEFT JOIN master.sys.syslogins u
ON j.owner_sid = u.sid
ORDER BY j.NAME
Comments
Post a Comment