Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Is there a way to query the owner of all jobs in SQL Server 2008 R2? I discovered when maintenance plans are edited the owner gets changed, so I want to make sure they are all owned by sa.

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

This will generate the commands to change all non-sa-owned jobs to sa. You just need to copy and paste from the results pane to the top pane (or a new query window), and execute.

SELECT 'EXEC msdb.dbo.sp_update_job @job_id = ''' 
        + CONVERT(VARCHAR(36), job_id) 
        + ''', @owner_login_name = ''sa'';'
    FROM msdb.dbo.sysjobs
    WHERE owner_sid <> 0x01;
share|improve this answer
add comment
SELECT 
     name
   , SUSER_SNAME(owner_sid) AS owner 
FROM msdb.dbo.sysjobs;
share|improve this answer
add comment
select 
    sj.name,
    description,
    SUSER_sNAME(owner_sid)
from msdb.dbo.sysjobs sj;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.