UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.9.8.7';
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TBEDMI_ITEM_FILES](
	[GUID] [bigint] IDENTITY(1,1) NOT NULL,
	[REFERENCE_GUID] [varchar](250) NOT NULL,
	[ITEM_VALUE] [varbinary](max) NOT NULL,
	[ORG_FILENAME] [varchar](256) NOT NULL,
	[MIME_TYPE] [varchar](256) NOT NULL,
	[GROUP_INDEX] [int] NOT NULL,
	[CREATED_WHEN] [datetime] NOT NULL,
	[CREATED_WHO] [varchar](100) NULL,
	[CHANGED_WHEN] [datetime] NULL,
	[CHANGED_WHO] [varchar](100) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ADD  CONSTRAINT [DF_TBEDMI_ITEM_FILES_GROUP_INDEX]  DEFAULT ((0)) FOR [GROUP_INDEX]
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ADD  CONSTRAINT [DF_TBEDMI_ITEM_FILES_CREATED_WHEN]  DEFAULT (getdate()) FOR [CREATED_WHEN]
GO
CREATE TRIGGER [dbo].[TBEDMI_ITEM_FILES_AFT_UPD] ON [dbo].[TBEDMI_ITEM_FILES]
FOR UPDATE
AS
BEGIN 
	UPDATE TBEDMI_ITEM_FILES SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBEDMI_ITEM_FILES.GUID = INSERTED.GUID
END		
GO
ALTER TABLE [dbo].[TBEDMI_ITEM_FILES] ENABLE TRIGGER [TBEDMI_ITEM_FILES_AFT_UPD]
GO
ALTER TABLE dbo.TBDD_ZUGFERD_XML_ITEMS ADD
	EN16931_ID nvarchar(50) NULL
GO