﻿USE [DD_ECM]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [FK_TBEDI_XML_TYPES]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [FK_TBEDI_XML_NODES]
GO
ALTER TABLE [dbo].[TBEDI_XML_TYPES] DROP CONSTRAINT [DF_TBEDI_XML_TYPES_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TYPES] DROP CONSTRAINT [DF_TBEDI_XML_TYPES_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TEMPLATES] DROP CONSTRAINT [DF_TBEDI_XML_TEMPLATES_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TEMPLATES] DROP CONSTRAINT [DF_TBEDI_XML_TEMPLATES_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] DROP CONSTRAINT [DF_TBEDI_XML_TABLES_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] DROP CONSTRAINT [DF_TBEDI_XML_TABLES_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] DROP CONSTRAINT [DF_TBEDI_XML_NODES_IS_HEAD]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY] DROP CONSTRAINT [DF_TBEDI_XML_MAPPING_ENTITY_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY] DROP CONSTRAINT [DF_TBEDI_XML_MAPPING_ENTITY_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] DROP CONSTRAINT [DF_TBEDI_XML_MAPPING_CONFIG_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] DROP CONSTRAINT [DF_TBEDI_XML_MAPPING_CONFIG_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] DROP CONSTRAINT [DF_TBEDI_XML_VALUE_MAPPING_ORDER_KEY]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_REQUIRED]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_VISIBLE]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_READ_ONLY]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] DROP CONSTRAINT [DF_TBEDI_XML_ITEMS_ORDER_KEY]
GO
ALTER TABLE [dbo].[TBEDI_XML_FUNCTIONS] DROP CONSTRAINT [DF_TBEDI_XML_FUNCTIONS_ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_FUNCTIONS] DROP CONSTRAINT [DF_TBEDI_XML_FUNCTIONS_ADDED_WHO]
GO
/****** Object:  Table [dbo].[TBEDI_XML_MAPPING_ENTITY]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_MAPPING_ENTITY]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY]
GO
/****** Object:  Table [dbo].[TBEDI_XML_MAPPING_CONFIG]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_MAPPING_CONFIG]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG]
GO
/****** Object:  View [dbo].[VWEDI_XML_ITEMS]    Script Date: 19.11.2021 11:36:10 ******/
DROP VIEW [dbo].[VWEDI_XML_ITEMS]
GO
/****** Object:  Table [dbo].[TBEDI_XML_ITEMS]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_ITEMS]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_ITEMS]
GO
/****** Object:  Table [dbo].[TBEDI_XML_FUNCTIONS]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_FUNCTIONS]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_FUNCTIONS]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TYPES]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_TYPES]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_TYPES]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TEMPLATES]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_TEMPLATES]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_TEMPLATES]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TABLES]    Script Date: 19.11.2021 11:36:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TBEDI_XML_TABLES]') AND type in (N'U'))
DROP TABLE [dbo].[TBEDI_XML_TABLES]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TABLES]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_TABLES](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](max) NOT NULL,
	[TEMPLATE_ID] [int] NOT NULL,
	[IS_HEAD] [bit] NOT NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK__TBEDI_XM__15B69B8E6F74D014] 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] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TEMPLATES]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_TEMPLATES](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](20) NOT NULL,
	[DESCRIPTION] [nvarchar](max) NULL,
	[FILE_NAME] [nvarchar](100) NULL,
	[IS_IMPORT] [bit] NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK__TBEDI_XM__15B69B8E8C482F3B] 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] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TBEDI_XML_TYPES]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_TYPES](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](20) NOT NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK__TBEDI_XM__15B69B8E5B32E7AF] 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
/****** Object:  Table [dbo].[TBEDI_XML_FUNCTIONS]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_FUNCTIONS](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](max) NOT NULL,
	[DESCRIPTION] [nvarchar](max) NOT NULL,
	[PARAMETERS] [nvarchar](max) NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
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] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TBEDI_XML_ITEMS]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_ITEMS](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[ORDER_KEY] [int] NOT NULL,
	[XML_NAME] [nvarchar](50) NOT NULL,
	[XML_TABLE_ID] [int] NOT NULL,
	[XML_TYPE_ID] [int] NOT NULL,
	[IS_READ_ONLY] [bit] NOT NULL,
	[IS_VISIBLE] [bit] NOT NULL,
	[IS_REQUIRED] [bit] NOT NULL,
	[FUNCTION_ID] [int] NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL,
 CONSTRAINT [PK__TBEDI_XM__15B69B8E6125D501] 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
/****** Object:  View [dbo].[VWEDI_XML_ITEMS]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE VIEW [dbo].[VWEDI_XML_ITEMS]
AS
	SELECT DISTINCT
		[TBTEMPLATES].[NAME] [TEMPLATE_NAME]
		,[TBTABLES].[NAME] AS [XML_TABLE]
		,[TBITEMS].[XML_NAME] AS [XML_ITEM]		
		,[TBTYPES].[NAME] AS [DATA_TYPE]
		,[TBTABLES].[IS_HEAD] AS [IS_HEAD]
		,[TBITEMS].[IS_READ_ONLY]
		,[TBITEMS].[IS_VISIBLE]
        ,[TBITEMS].[IS_REQUIRED]
		,[TBITEMS].[ORDER_KEY]
		,[TBFUNCTIONS].[GUID] AS [FUNCTION_ID]
		,[TBFUNCTIONS].[NAME] AS [FUNCTION_NAME]
		,[TBFUNCTIONS].[PARAMETERS] AS [FUNCTION_PARAMETERS]
	FROM
		[dbo].[TBEDI_XML_ITEMS] [TBITEMS]
		INNER JOIN [dbo].[TBEDI_XML_TABLES] [TBTABLES] ON [TBITEMS].[XML_TABLE_ID] = [TBTABLES].[GUID]
		INNER JOIN [dbo].[TBEDI_XML_TYPES] [TBTYPES] ON [TBITEMS].[XML_TYPE_ID] = [TBTYPES].[GUID]
		INNER JOIN [dbo].[TBEDI_XML_TEMPLATES] [TBTEMPLATES] ON [TBTABLES].[TEMPLATE_ID] = [TBTEMPLATES].[GUID]
		LEFT OUTER JOIN [dbo].[TBEDI_XML_FUNCTIONS] [TBFUNCTIONS] ON [TBITEMS].[FUNCTION_ID] = [TBFUNCTIONS].[GUID]
		
GO
/****** Object:  Table [dbo].[TBEDI_XML_MAPPING_CONFIG]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[ORDER_KEY] [int] NOT NULL,
	[SOURCE_ENTITY_ID] [int] NOT NULL,
	[SOURCE_REGEX] [nvarchar](100) NOT NULL,
	[DESTINATION_ENTITY_ID] [int] NOT NULL,
	[DESTINATION_VALUE] [nvarchar](100) NOT NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [nchar](10) NULL
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[TBEDI_XML_MAPPING_ENTITY]    Script Date: 19.11.2021 11:36:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY](
	[GUID] [int] IDENTITY(1,1) NOT NULL,
	[NAME] [nvarchar](100) NULL,
	[ADDED_WHO] [nvarchar](50) NOT NULL,
	[ADDED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [nvarchar](50) NULL,
	[CHANGED_WHEN] [datetime] NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_FUNCTIONS] ON 

INSERT [dbo].[TBEDI_XML_FUNCTIONS] ([GUID], [NAME], [DESCRIPTION], [PARAMETERS], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, N'GLN', N'Finds an WinLine Account Number by GLN', NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_FUNCTIONS] ([GUID], [NAME], [DESCRIPTION], [PARAMETERS], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, N'EAN', N'Finds an WinLine Article Number by EAN', NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_FUNCTIONS] ([GUID], [NAME], [DESCRIPTION], [PARAMETERS], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (3, N'SQL', N'Finds a Value by SQL Query', N'Query', N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_FUNCTIONS] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_ITEMS] ON 

INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, 0, N'BELEGKEY', 1, 1, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, 0, N'Fakt_Kontonummer', 1, 1, 0, 1, 0, 1, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (3, 0, N'Laufnummer', 1, 1, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (4, 0, N'Bestellt_von', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (5, 0, N'Lief_Kontonummer', 1, 1, 0, 1, 0, 1, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (6, 0, N'Lief_Name', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (7, 0, N'Lief_Strasse', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (8, 0, N'Lief_PLZ', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (9, 0, N'Lief_Ort', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (10, 0, N'Belegart', 1, 2, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (11, 0, N'Datum_Auftrag-Bestellung', 1, 3, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (12, 0, N'Auftrags-Bestellnummer', 1, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (13, 0, N'Leistungsdatum', 1, 3, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (14, 0, N'Infotext', 1, 1, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (15, 0, N'BELEGKEY', 2, 1, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (16, 1, N'Zeilennummer', 2, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (17, 0, N'Datentyp', 2, 2, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (18, 2, N'Artikelnummer', 2, 1, 0, 1, 0, 2, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (19, 3, N'Bezeichnung', 2, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (20, 0, N'Lieferantenartikelnummer', 2, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (21, 0, N'Menge_bestellt', 2, 5, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (22, 0, N'Menge_geliefert', 2, 5, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (23, 0, N'Colli', 2, 1, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (24, 0, N'Einzelpreis', 2, 5, 0, 1, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (25, 0, N'Zeilenrabatt1', 2, 5, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (26, 0, N'Zeilenrabatt2', 2, 5, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (27, 0, N'Zeilenrabatt3', 2, 5, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (28, 0, N'Zeilenrabatt4', 2, 5, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (29, 0, N'Umsatzsteuerprozent_Zeile', 2, 2, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_ITEMS] ([GUID], [ORDER_KEY], [XML_NAME], [XML_TABLE_ID], [XML_TYPE_ID], [IS_READ_ONLY], [IS_VISIBLE], [IS_REQUIRED], [FUNCTION_ID], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (30, 0, N'EDI_Infotext', 2, 1, 0, 0, 0, NULL, N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_ITEMS] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_MAPPING_CONFIG] ON 

INSERT [dbo].[TBEDI_XML_MAPPING_CONFIG] ([GUID], [ORDER_KEY], [SOURCE_ENTITY_ID], [SOURCE_REGEX], [DESTINATION_ENTITY_ID], [DESTINATION_VALUE], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, 1, 2, N'^R[a-zA-Z0-9\-_\s]+$', 1, N'SHGT', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_MAPPING_CONFIG] ([GUID], [ORDER_KEY], [SOURCE_ENTITY_ID], [SOURCE_REGEX], [DESTINATION_ENTITY_ID], [DESTINATION_VALUE], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (3, 2, 2, N'NIE\-[a-zA-Z0-9]*', 1, N'SIVT', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_MAPPING_CONFIG] ([GUID], [ORDER_KEY], [SOURCE_ENTITY_ID], [SOURCE_REGEX], [DESTINATION_ENTITY_ID], [DESTINATION_VALUE], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (5, 3, 2, N'NIE\-[a-zA-Z0-9]*', 3, N'106', N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_MAPPING_CONFIG] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_MAPPING_ENTITY] ON 

INSERT [dbo].[TBEDI_XML_MAPPING_ENTITY] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, N'MANDATOR', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_MAPPING_ENTITY] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, N'ARTICLE', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_MAPPING_ENTITY] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (3, N'DOCUMENTTYPE', N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_MAPPING_ENTITY] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TABLES] ON 

INSERT [dbo].[TBEDI_XML_TABLES] ([GUID], [NAME], [TEMPLATE_ID], [IS_HEAD], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, N'EXIM-VRG_ordersT025', 1, 1, N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TABLES] ([GUID], [NAME], [TEMPLATE_ID], [IS_HEAD], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, N'EXIM-VRG_ordersT026', 1, 0, N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TABLES] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TEMPLATES] ON 

INSERT [dbo].[TBEDI_XML_TEMPLATES] ([GUID], [NAME], [DESCRIPTION], [FILE_NAME], [IS_IMPORT], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, N'EXIM-VRG_orders', N'Schaum EDI Aufträge', N'MESOBelegeEXIM-VRG_orders.xsd', 1, N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TEMPLATES] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TYPES] ON 

INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (1, N'STRING', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (2, N'INTEGER', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (3, N'DATE', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (4, N'BOOLEAN', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (5, N'DECIMAL', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (6, N'ACCOUNT', N'DEFAULT', NULL, NULL, NULL)
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME], [ADDED_WHO], [ADDED_WHEN], [CHANGED_WHO], [CHANGED_WHEN]) VALUES (7, N'ARTICLE', N'DEFAULT', NULL, NULL, NULL)
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TYPES] OFF
GO
ALTER TABLE [dbo].[TBEDI_XML_FUNCTIONS] ADD  CONSTRAINT [DF_TBEDI_XML_FUNCTIONS_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_FUNCTIONS] ADD  CONSTRAINT [DF_TBEDI_XML_FUNCTIONS_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_ORDER_KEY]  DEFAULT ((0)) FOR [ORDER_KEY]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_READ_ONLY]  DEFAULT ((0)) FOR [IS_READ_ONLY]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_VISIBLE]  DEFAULT ((0)) FOR [IS_VISIBLE]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_IS_REQUIRED]  DEFAULT ((0)) FOR [IS_REQUIRED]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] ADD  CONSTRAINT [DF_TBEDI_XML_ITEMS_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] ADD  CONSTRAINT [DF_TBEDI_XML_VALUE_MAPPING_ORDER_KEY]  DEFAULT ((0)) FOR [ORDER_KEY]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] ADD  CONSTRAINT [DF_TBEDI_XML_MAPPING_CONFIG_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_CONFIG] ADD  CONSTRAINT [DF_TBEDI_XML_MAPPING_CONFIG_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY] ADD  CONSTRAINT [DF_TBEDI_XML_MAPPING_ENTITY_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_MAPPING_ENTITY] ADD  CONSTRAINT [DF_TBEDI_XML_MAPPING_ENTITY_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] ADD  CONSTRAINT [DF_TBEDI_XML_NODES_IS_HEAD]  DEFAULT ((0)) FOR [IS_HEAD]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] ADD  CONSTRAINT [DF_TBEDI_XML_TABLES_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TABLES] ADD  CONSTRAINT [DF_TBEDI_XML_TABLES_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TEMPLATES] ADD  CONSTRAINT [DF_TBEDI_XML_TEMPLATES_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TEMPLATES] ADD  CONSTRAINT [DF_TBEDI_XML_TEMPLATES_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_TYPES] ADD  CONSTRAINT [DF_TBEDI_XML_TYPES_ADDED_WHO]  DEFAULT (N'DEFAULT') FOR [ADDED_WHO]
GO
ALTER TABLE [dbo].[TBEDI_XML_TYPES] ADD  CONSTRAINT [DF_TBEDI_XML_TYPES_ADDED_WHEN]  DEFAULT (getdate()) FOR [ADDED_WHEN]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS]  WITH CHECK ADD  CONSTRAINT [FK_TBEDI_XML_NODES] FOREIGN KEY([XML_TABLE_ID])
REFERENCES [dbo].[TBEDI_XML_ITEMS] ([GUID])
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] CHECK CONSTRAINT [FK_TBEDI_XML_NODES]
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS]  WITH CHECK ADD  CONSTRAINT [FK_TBEDI_XML_TYPES] FOREIGN KEY([XML_TYPE_ID])
REFERENCES [dbo].[TBEDI_XML_ITEMS] ([GUID])
GO
ALTER TABLE [dbo].[TBEDI_XML_ITEMS] CHECK CONSTRAINT [FK_TBEDI_XML_TYPES]
GO
