Add updated SqlAgent folder
This commit is contained in:
27
SqlAgent/01_Devl/4_Job_Maintenance/DeleteSchedule.sql
Normal file
27
SqlAgent/01_Devl/4_Job_Maintenance/DeleteSchedule.sql
Normal file
@ -0,0 +1,27 @@
|
||||
USE msdb;
|
||||
GO
|
||||
|
||||
DECLARE @EnvPrefix NVARCHAR(50) = N'DEVL'; -- <<< Change this to your environment prefix
|
||||
DECLARE @schedule_id INT;
|
||||
DECLARE @schedule_name NVARCHAR(128);
|
||||
|
||||
DECLARE Sched_Cursor CURSOR FOR
|
||||
SELECT schedule_id, name
|
||||
FROM msdb.dbo.sysschedules
|
||||
WHERE name LIKE @EnvPrefix + '%'; -- Only schedules starting with the given prefix
|
||||
|
||||
OPEN Sched_Cursor;
|
||||
FETCH NEXT FROM Sched_Cursor INTO @schedule_id, @schedule_name;
|
||||
|
||||
WHILE @@FETCH_STATUS = 0
|
||||
BEGIN
|
||||
PRINT 'Deleting schedule: ' + @schedule_name;
|
||||
EXEC msdb.dbo.sp_delete_schedule @schedule_id = @schedule_id;
|
||||
FETCH NEXT FROM Sched_Cursor INTO @schedule_id, @schedule_name;
|
||||
END
|
||||
|
||||
CLOSE Sched_Cursor;
|
||||
DEALLOCATE Sched_Cursor;
|
||||
|
||||
PRINT 'All SQL Agent schedules starting with prefix ' + @EnvPrefix + ' deleted successfully.';
|
||||
GO
|
||||
Reference in New Issue
Block a user