USE msdb;
GO

DECLARE @EnvPrefix NVARCHAR(50) = N'DEVL';  -- <<< Change this to your environment prefix
DECLARE @job_id UNIQUEIDENTIFIER;
DECLARE @job_name NVARCHAR(200);

DECLARE JobCursor CURSOR FOR
SELECT job_id, name
FROM msdb.dbo.sysjobs
WHERE name LIKE @EnvPrefix + '%';   -- Only jobs starting with the given prefix

OPEN JobCursor;
FETCH NEXT FROM JobCursor INTO @job_id, @job_name;

WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT 'Deleting job: ' + @job_name;
    EXEC msdb.dbo.sp_delete_job @job_id = @job_id;
    FETCH NEXT FROM JobCursor INTO @job_id, @job_name;
END

CLOSE JobCursor;
DEALLOCATE JobCursor;

PRINT 'All SQL Agent jobs starting with prefix ' + @EnvPrefix + ' deleted successfully.';
GO
