SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBDEX_CFG_RESOURCES](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[PROFILE_ID] [bigint] NOT NULL,
	[ACTIVE] [bit] NOT NULL,
	[SEQUENCE] [tinyint] NOT NULL,
	[PLACEHOLDER_NAME] [nvarchar](50) NOT NULL,
	[PLACEHOLDER_TYPE] [nvarchar](10) NOT NULL,
	[PLACEHOLDER] [nvarchar](max) NOT NULL,
	[ERROR_ACTION] [smallint] NULL,
	[COMMENT] [nvarchar](250) NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NOT NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK_TBDEX_CFG_RESOURCES] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (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_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_ACTIVE]  DEFAULT ((1)) FOR [ACTIVE]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_SEQUENCE]  DEFAULT ((0)) FOR [SEQUENCE]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_PLACEHOLDER_NAME]  DEFAULT ('DEFAULT') FOR [PLACEHOLDER_NAME]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_PLACEHOLDER_TYPE]  DEFAULT ('VALUE') FOR [PLACEHOLDER_TYPE]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_ERROR_ACTION]  DEFAULT ((0)) FOR [ERROR_ACTION]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_ADDED_WHO]  DEFAULT ('DEFAULT') FOR [ADDED_WHO]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] ADD  CONSTRAINT [DF_TBDEX_CFG_RESOURCES_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES]  WITH NOCHECK ADD  CONSTRAINT [FK_TBDEX_CFG_RESOURCES_TBDEX_CFG_PROFILE] FOREIGN KEY([PROFILE_ID])
REFERENCES [dbo].[TBDEX_CFG_PROFILE] ([GUID])
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] NOCHECK CONSTRAINT [FK_TBDEX_CFG_RESOURCES_TBDEX_CFG_PROFILE]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES]  WITH CHECK ADD  CONSTRAINT [CK_TBDEX_CFG_RESOURCES_PLACEHOLDER_TYPE] CHECK  ((upper([PLACEHOLDER_TYPE])='QUERY' OR upper([PLACEHOLDER_TYPE])='CONST'))
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] CHECK CONSTRAINT [CK_TBDEX_CFG_RESOURCES_PLACEHOLDER_TYPE]
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES]  WITH CHECK ADD  CONSTRAINT [CK_TBDEX_CFG_RESOURCES_ERROR_ACTION] CHECK  (([ERROR_ACTION]=(0) OR [ERROR_ACTION]=(1)))
GO

ALTER TABLE [dbo].[TBDEX_CFG_RESOURCES] CHECK CONSTRAINT [CK_TBDEX_CFG_RESOURCES_ERROR_ACTION]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Fehlerbehandlung (0 = STOP; 1 = CONTINUE)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TBDEX_CFG_RESOURCES', @level2type=N'COLUMN',@level2name=N'ERROR_ACTION'
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_CFG_RESOURCES', @level2type=N'CONSTRAINT',@level2name=N'FK_TBDEX_CFG_RESOURCES_TBDEX_CFG_PROFILE'
GO


