One way to check the owner of SQL Server agent Job is to Right Click on Job and go to Properties and then see the Owner.
If we need to get the owners for all the SQL Server Agent Job, that can be time consuming. We often need this information for Audit. We can use system objects such as sysjobs and syslogins from MSDB to get this information.
If you see Null value in OwnerName that means that the login does not exists for the account used in Job as owner. It is good time to take care of that.
You can use below query to return all job names with owners, even for those logins does not exists.
SELECT J.NAME AS JobName ,L.NAME AS OwnerName FROM msdb..sysjobs J LEFT JOIN master.sys.syslogins L ON J.owner_sid = L.sid
You can use below query to return all job names with owners, even for those logins does not exists.
SELECT NAME AS JobName ,SUSER_SNAME(owner_sid) AS JobOwner FROM msdb..sysjobs ORDER BY NAME
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.