﻿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_TABLES] DROP CONSTRAINT [DF_TBEDI_XML_NODES_IS_HEAD]
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_ORDER_KEY]
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
/****** Object:  View [dbo].[VWEDI_XML_ITEMS]    Script Date: 18.11.2021 13:29:24 ******/
DROP VIEW [dbo].[VWEDI_XML_ITEMS]
GO
/****** Object:  Table [dbo].[TBEDI_XML_ITEMS]    Script Date: 18.11.2021 13:29:24 ******/
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_TABLES]    Script Date: 18.11.2021 13:29:24 ******/
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_FUNCTIONS]    Script Date: 18.11.2021 13:29:24 ******/
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: 18.11.2021 13:29:24 ******/
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: 18.11.2021 13:29:24 ******/
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_TEMPLATES]    Script Date: 18.11.2021 13:29:24 ******/
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,
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: 18.11.2021 13:29:24 ******/
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,
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: 18.11.2021 13:29:24 ******/
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,
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_TABLES]    Script Date: 18.11.2021 13:29:24 ******/
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,
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: 18.11.2021 13:29:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDI_XML_ITEMS](
	[GUID] [int] IDENTITY(1,1) 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,
	[ORDER_KEY] [int] NOT NULL,
	[FUNCTION_ID] [int] NULL,
	[IS_REQUIRED] [bit] NOT 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]
GO
/****** Object:  View [dbo].[VWEDI_XML_ITEMS]    Script Date: 18.11.2021 13:29:24 ******/
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
SET IDENTITY_INSERT [dbo].[TBEDI_XML_FUNCTIONS] ON 

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

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

INSERT [dbo].[TBEDI_XML_TABLES] ([GUID], [NAME], [TEMPLATE_ID], [IS_HEAD]) VALUES (1, N'EXIM-VRG_ordersT025', 1, 1)
INSERT [dbo].[TBEDI_XML_TABLES] ([GUID], [NAME], [TEMPLATE_ID], [IS_HEAD]) VALUES (2, N'EXIM-VRG_ordersT026', 1, 0)
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]) VALUES (1, N'EXIM-VRG_orders', N'Schaum EDI Aufträge')
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TEMPLATES] OFF
GO
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TYPES] ON 

INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (1, N'STRING')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (2, N'INTEGER')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (3, N'DATE')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (4, N'BOOLEAN')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (5, N'DECIMAL')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (6, N'ACCOUNT')
INSERT [dbo].[TBEDI_XML_TYPES] ([GUID], [NAME]) VALUES (7, N'ARTICLE')
SET IDENTITY_INSERT [dbo].[TBEDI_XML_TYPES] OFF
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_ORDER_KEY]  DEFAULT ((0)) FOR [ORDER_KEY]
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_TABLES] ADD  CONSTRAINT [DF_TBEDI_XML_NODES_IS_HEAD]  DEFAULT ((0)) FOR [IS_HEAD]
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
