
/****** Object:  Table [dbo].[ValueMapping]    Script Date: 09.05.2023 13:21:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[ValueMapping](
	[Id] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
	[EntryType] [tinyint] NULL,
	[MappingKey] [nvarchar](64) NULL,
	[MappingValue] [nvarchar](128) NULL,
	[Created] [datetime] NOT NULL,
	[Changed] [datetime] NULL,
 CONSTRAINT [PK_ValueMapping] PRIMARY KEY CLUSTERED 
(
	[Id] 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

ALTER TABLE [dbo].[ValueMapping] ADD  CONSTRAINT [DF_ValueMapping_Id]  DEFAULT (newid()) FOR [Id]
GO

ALTER TABLE [dbo].[ValueMapping] ADD  CONSTRAINT [DF_ValueMapping_Created]  DEFAULT (getdate()) FOR [Created]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE trigger [dbo].[ValueMapping_Trigger_Change_Log]
ON [dbo].[ValueMapping]
FOR UPDATE
AS
  SET NOCOUNT ON
  IF NOT UPDATE([Changed])
    UPDATE ValueMapping SET [Changed] = GETDATE() WHERE Id IN (SELECT Id FROM [inserted])
GO
ALTER TABLE [dbo].[ValueMapping] ENABLE TRIGGER [ValueMapping_Trigger_Change_Log]
GO