我在 SQL 2005 数据库上禁用了日志传送,并删除了辅助服务器上的日志传送数据库。但是,我无法通过 T-SQL(sp_delete_log_shipping_primary_secondary、sp_delete_job)或使用辅助服务器上的管理工作室来删除 LSRestore_DB___ 作业。它只是不会去。查询持续执行了 7 个小时。试过禁用,还是删不掉。也重启了服务器。还尝试了谁能帮我删除这个 SQL 作业吗?
问问题
830 次
2 回答
1
有一篇很好的文章不能删除作业。在文章中作者提供了一个脚本来解决这个问题,干得好!
`CREATE PROC dbo.DropJob
@JobName AS VARCHAR(200) = NULL
AS
DECLARE @msg AS VARCHAR(500);
IF @JobName IS NULL
BEGIN
SET @msg = N'A job name must be supplied for parameter @JobName.';
RAISERROR(@msg,16,1);
RETURN;
END
IF EXISTS (
SELECT subplan_id FROM msdb.dbo.sysmaintplan_log WHERE subplan_id IN
( SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName)))
BEGIN
DELETE FROM msdb.dbo.sysmaintplan_log WHERE subplan_id IN
( SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName));
DELETE FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName);
EXEC msdb.dbo.sp_delete_job @job_name=@JobName, @delete_unused_schedule=1;
END
ELSE IF EXISTS (
SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName))
BEGIN
DELETE FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName);
EXEC msdb.dbo.sp_delete_job @job_name=@JobName, @delete_unused_schedule=1;
END
ELSE
BEGIN
EXEC msdb.dbo.sp_delete_job @job_name=@JobName, @delete_unused_schedule=1;
END
GO`
现在您可以使用以下命令调用 SP;
`USE [msdb];
EXEC dbo.DropJob @JobName = N'Shrink_AWP_Databases.Subplan_1';`
于 2013-10-31T06:30:42.390 回答
0
您是否尝试过设置允许编辑系统表,并直接进入保存作业信息的系统表并尝试从那里删除行?
确保在执行此操作时要格外小心,不推荐,但有时需要直接编辑系统表。
于 2009-11-25T10:15:02.160 回答