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?
1 Answer
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'
-
This works in the case of the distributor being on the same SQL instance as the publisher - but is there a way to do this if the we are executing on a remote publisher?– MikeCommented Apr 3, 2018 at 5:28