如果(并且仅当)它存在,我如何删除sql server代理作业?
这是一个运行良好的存储过程脚本.如何对sql server agent作业执行相同的操作?
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storedproc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[storedproc] GO CREATE PROCEDURE [dbo].[storedproc] ...
Codewerks.. 86
尝试这样的事情:
DECLARE @jobId binary(16) SELECT @jobId = job_id FROM msdb.dbo.sysjobs WHERE (name = N'Name of Your Job') IF (@jobId IS NOT NULL) BEGIN EXEC msdb.dbo.sp_delete_job @jobId END DECLARE @ReturnCode int EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Name of Your Job'
最好阅读'sp_add_job'和'sp_delete_job'所需的所有参数的文档
尝试这样的事情:
DECLARE @jobId binary(16) SELECT @jobId = job_id FROM msdb.dbo.sysjobs WHERE (name = N'Name of Your Job') IF (@jobId IS NOT NULL) BEGIN EXEC msdb.dbo.sp_delete_job @jobId END DECLARE @ReturnCode int EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Name of Your Job'
最好阅读'sp_add_job'和'sp_delete_job'所需的所有参数的文档
IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'Your Job Name') EXEC msdb.dbo.sp_delete_job @job_name=N'Your Job Name' , @delete_unused_schedule=1