-- Name:
-- sp_MSdrop_repl_job
-- Description:
-- 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.
-- Parameters:
-- See definition
-- Returns:
-- 0 - succeeded
-- 1 - failed
-- Result:
-- None
-- Security:
-- 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
)
AS
BEGIN
DECLARE @retcode int,
@job_found bit
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
BEGIN
RETURN 1
END
-- we exit without failure if the job was not found
IF @job_found = 0
BEGIN
RETURN 0
END
-- 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
RETURN @retcode
END