USE [DD_ECM]
GO


CREATE TABLE [dbo].[TBAPPSERV_CRON_JOB](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[TITLE] [varchar](100) NOT NULL,
	[CRON_DEFINITION] [varchar](500) NOT NULL,
	[ACTIVE] [bit] NOT NULL,
	[COMMENT] [varchar](500) NULL,
	[ADDED_WHO] [varchar](100) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [varchar](100) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK_TBAPPSERV_CRON_JOB] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ1_TBAPPSERV_CRON_JOB] UNIQUE NONCLUSTERED 
(
	[CRON_DEFINITION] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ2_TBAPPSERV_CRON_JOB] UNIQUE NONCLUSTERED 
(
	[TITLE] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_JOB] ADD  DEFAULT ((0)) FOR [ACTIVE]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_JOB] ADD  DEFAULT ('Digital Data') FOR [ADDED_WHO]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_JOB] ADD  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO


CREATE TABLE [dbo].[TBAPPSERV_CRON_DETAIL](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[CRON_ID] [int] NOT NULL,
	[CON_ID] [smallint] NOT NULL,
	[TITLE] [varchar](100) NOT NULL,
	[DT_NAME] [varchar](100) NOT NULL,
	[RUN_ON_STARTUP] [bit] NOT NULL,
	[MAN_RENEW] [bit] NOT NULL,
	[COMMAND] [nvarchar](max) NOT NULL,
	[ADDED_WHO] [varchar](100) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [varchar](100) NULL,
	[CHANGED_WHEN] [datetime] NULL,
	[CHILD_DT_NAME] [varchar](100) NULL,
	[CHILD_DT_COLUMN] [varchar](100) NULL,
	[DT_COLUMN] [varchar](100) NULL,
 CONSTRAINT [PK_TBAPPSERV_CRON_DETAIL] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ_TBAPPSERV_CRON_DETAIL_DT_NAME] UNIQUE NONCLUSTERED 
(
	[DT_NAME] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UQ_TBAPPSERV_CRON_DETAIL_TITLE] UNIQUE NONCLUSTERED 
(
	[TITLE] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] ADD  DEFAULT ((0)) FOR [RUN_ON_STARTUP]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] ADD  DEFAULT ((0)) FOR [MAN_RENEW]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] ADD  DEFAULT ('Digital Data') FOR [ADDED_WHO]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] ADD  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL]  WITH CHECK ADD  CONSTRAINT [FK_TBAPPSERV_CRON_DETAIL_CON_ID] FOREIGN KEY([CON_ID])
REFERENCES [dbo].[TBDD_CONNECTION] ([GUID])
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] CHECK CONSTRAINT [FK_TBAPPSERV_CRON_DETAIL_CON_ID]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL]  WITH CHECK ADD  CONSTRAINT [FK_TBAPPSERV_CRON_DETAIL_CRON_ID] FOREIGN KEY([CRON_ID])
REFERENCES [dbo].[TBAPPSERV_CRON_JOB] ([GUID])
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] CHECK CONSTRAINT [FK_TBAPPSERV_CRON_DETAIL_CRON_ID]
GO



/****** Object:  Table [dbo].[TBAPPSERV_CRON_DETAIL_HISTORY]    Script Date: 22.12.2020 09:37:33 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBAPPSERV_CRON_DETAIL_HISTORY](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[DETAIL_ID] [int] NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
 CONSTRAINT [PK_TBAPPSERV_CRON_DETAIL_HISTORY] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL_HISTORY] ADD  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL_HISTORY]  WITH CHECK ADD  CONSTRAINT [FK_TTBAPPSERV_CRON_DETAIL_HISTORY_DETAIL_ID] FOREIGN KEY([DETAIL_ID])
REFERENCES [dbo].[TBAPPSERV_CRON_DETAIL] ([GUID])
GO

ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL_HISTORY] CHECK CONSTRAINT [FK_TTBAPPSERV_CRON_DETAIL_HISTORY_DETAIL_ID]
GO
CREATE PROCEDURE PRAPPSERV_DAILY_JOB
AS
BEGIN
	DELETE FROM TBAPPSERV_CRON_DETAIL_HISTORY 
	where DATEDIFF(DAY,ADDED_WHEN,GETDATE()) > 2
END

GO
ALTER TABLE [dbo].[TBAPPSERV_CRON_DETAIL] ADD INDEX_COLUMNS VARCHAR(255) NOT NULL DEFAULT '';
GO



