USE [DD_ECM]
GO

/****** Object:  Table [dbo].[TBDEX_RUN_LOG]    Script Date: 07.12.2025 23:25:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBDEX_RUN_LOG](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[PROFILE_ID] [bigint] NOT NULL,
	[BATCH_ID] [nvarchar](25) NULL,
	[LOG_LEVEL] [nvarchar](25) NOT NULL,
	[REFERENCE1] [nvarchar](150) NULL,
	[REFERENCE2] [nvarchar](150) NULL,
	[REFERENCE3] [nvarchar](150) NULL,
	[REFERENCE4] [nvarchar](150) NULL,
	[REFERENCE5] [nvarchar](150) NULL,
	[RETURN_CODE] [int] NOT NULL,
	[MESSAGE1] [nvarchar](max) NOT NULL,
	[MESSAGE2] [nvarchar](max) NULL,
	[MESSAGE3] [nvarchar](max) NULL,
	[MESSAGE4] [nvarchar](max) NULL,
	[MESSAGE5] [nvarchar](max) NULL,
	[COMMENT] [nvarchar](250) NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NOT NULL,
 CONSTRAINT [PK_TBDEX_RUN_LOG_GUID] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (DATA_COMPRESSION = PAGE, PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_REFERENCE1]  DEFAULT ((0)) FOR [PROFILE_ID]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_LOG_LEVEL]  DEFAULT ('UNKNOWN') FOR [LOG_LEVEL]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_RETURN_CODE]  DEFAULT ((0)) FOR [RETURN_CODE]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_MESSAGE1]  DEFAULT ('NO MESSAGE GIVEN') FOR [MESSAGE1]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_ADDED_WHO]  DEFAULT ('DEFAULT') FOR [ADDED_WHO]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] ADD  CONSTRAINT [DF_TBDEX_RUN_LOG_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG]  WITH CHECK ADD  CONSTRAINT [FK_TBDEX_RUN_LOG_TBDEX_CFG_PROFILE] FOREIGN KEY([PROFILE_ID])
REFERENCES [dbo].[TBDEX_CFG_PROFILE] ([GUID])
GO

ALTER TABLE [dbo].[TBDEX_RUN_LOG] CHECK CONSTRAINT [FK_TBDEX_RUN_LOG_TBDEX_CFG_PROFILE]
GO

CREATE NONCLUSTERED INDEX [IX_TBDEX_RUN_LOG_PROFILE_BATCH] ON [dbo].[TBDEX_RUN_LOG]
(
	[PROFILE_ID] ASC,
	[BATCH_ID] ASC,
	[ADDED_WHEN] DESC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = ON, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Link PROFILE_ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TBDEX_RUN_LOG', @level2type=N'CONSTRAINT',@level2name=N'FK_TBDEX_RUN_LOG_TBDEX_CFG_PROFILE'
GO


