USE [DevlDUTASJobSchedule];
GO

/**************************************************************************************************
-- FILE: JobDependencies.sql
-- PURPOSE: Manage JobDependencies table - Create, Read, Update, Delete for a single dependency
-- TABLE: dbo.JobDependencies
**************************************************************************************************/

-------------------------------
-- SELECT - View Dependency
-------------------------------
SELECT *
FROM [dbo].[JobDependencies]
WHERE [JobName] = N'PROD_DAILY_DTSGSID0';
GO

-------------------------------
-- INSERT - Create Dependency
-------------------------------
INSERT INTO [dbo].[JobDependencies]
(
    [JobName],
    [PredecessorJobName]
)
VALUES
(
    N'PROD_DAILY_DTSGSID0',   -- Dependent job
    N'PROD_DAILY_DTSBX305'    -- Predecessor job
);
GO

-------------------------------
-- UPDATE - Modify Dependency
-------------------------------
UPDATE [dbo].[JobDependencies]
SET [PredecessorJobName] = N'PROD_DAILY_DTSBX215'
WHERE [JobName] = N'PROD_DAILY_DTSGSID0'
  AND [PredecessorJobName] = N'PROD_DAILY_DTSBX305';
GO

-------------------------------
-- DELETE - Remove Dependency
-------------------------------
DELETE FROM [dbo].[JobDependencies]
WHERE [JobName] = N'PROD_DAILY_DTSGSID0'
  AND [PredecessorJobName] = N'PROD_DAILY_DTSBX215';
GO

-------------------------------
-- SELECT - View Dependency
-------------------------------
SELECT *
FROM [dbo].[JobDependencies]
WHERE [JobName] = N'PROD_DAILY_DTSGSID0';
GO
