-- This procedure should be used to drop replication jobs.
-- Here we validate that the job being dropped is replication
-- related and in certain cases we check to see if the current
-- user is a sysadmin or that the current database context is
-- the same as the on used when creating the job. We also check
-- to ensure that the job exists. If it does not exist we exit
-- without failure.
-- See definition
-- 0 - succeeded
-- 1 - failed
-- Procedure is NOT PUBLIC so there are no security checks.
-- We do however ensure that the job being dropped is replication
-- related. In certain jobs we also ensure that the user is sysadmin
-- or that the current database context is the same as the on used
-- when creating the job.
CREATE PROCEDURE sys.sp_MSdrop_repl_job
@job_name sysname = NULL,
@job_id binary(16) = NULL,
@job_step_uid uniqueidentifier = NULL
DECLARE @retcode int,
SELECT @job_found = 0
EXEC @retcode = sys.sp_MSrepl_check_job_access @id = @job_id,
@step_uid = @job_step_uid,
@name = @job_name,
@err_not_found = 0,
@job_found = @job_found output
IF @@ERROR <> 0 or @retcode <> 0
-- we exit without failure if the job was not found
IF @job_found = 0
-- call internal drop procedure
EXEC @retcode = sys.sp_MSdrop_repl_job_unsafe @job_name = @job_name,
@job_id = @job_id,
@job_step_uid = @job_step_uid