Use below script to disable all active Jobs in SQL Server:
BEGIN
SET NoCount On
DECLARE @JobName nVarChar(128), @Enabled int
SELECT Name, [Enabled] INTO #Temp_Jobs FROM msdb.dbo.sysjobs WHERE [Enabled] = 1
WHILE Exists(SELECT TOP 1 Name FROM #Temp_Jobs)
BEGIN
SELECT TOP 1 @JobName = Name, @Enabled = [Enabled] FROM #Temp_Jobs
PRINT ('Job Name: ' + Cast(@JobName AS nVarChar) + ' , Status: ' + Cast(@Enabled AS VarChar))
EXEC msdb.dbo.sp_update_job @Job_Name = @JobName , @Enabled = 0
DELETE FROM #Temp_Jobs WHERE Name = @JobName
END
DROP TABLE #Temp_Jobs
SET NoCount OFF
END
BEGIN
SET NoCount On
DECLARE @JobName nVarChar(128), @Enabled int
SELECT Name, [Enabled] INTO #Temp_Jobs FROM msdb.dbo.sysjobs WHERE [Enabled] = 1
WHILE Exists(SELECT TOP 1 Name FROM #Temp_Jobs)
BEGIN
SELECT TOP 1 @JobName = Name, @Enabled = [Enabled] FROM #Temp_Jobs
PRINT ('Job Name: ' + Cast(@JobName AS nVarChar) + ' , Status: ' + Cast(@Enabled AS VarChar))
EXEC msdb.dbo.sp_update_job @Job_Name = @JobName , @Enabled = 0
DELETE FROM #Temp_Jobs WHERE Name = @JobName
END
DROP TABLE #Temp_Jobs
SET NoCount OFF
END
No comments:
Post a Comment