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
