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.

I'm creating a script to recreate a database for test purposes, and the database has some publications. In order to create or not the logreader agent I need to know if the current database already has one, or destroy the existing agent prior to recreate the database. I know there is some class in SMO can do that, but I need to achieve the same with T-SQL. Someone can help?

share|improve this question
1  
I'm not currently by a test box, but if you can do this with SMO then just reverse engineer the SQL to accomplish this by using XEvents or creating a SQL Trace. –  Thomas Stringer Jan 4 at 2:04
add comment

1 Answer

up vote 1 down vote accepted

Below T-SQL will give you the log reader agent. You can use the agent name or job_id to drop/delete the log reader agent.

    SELECT SERVER
    ,[command]
    ,sj.job_id
    ,[NAME]
FROM msdb.dbo.sysjobs sj
INNER JOIN msdb.dbo.sysjobsteps sjs ON sjs.job_id = sj.job_id
    AND subsystem = 'logreader'
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.