PRINT N'Creating [dbo].[SERV_template]...';

GO
CREATE TABLE [dbo].[SERV_template] (
    [Id]                    UNIQUEIDENTIFIER NOT NULL,
    [ServiceName]           NVARCHAR (100)    NULL,
	[ServiceBeneficiary]	NVARCHAR (256)	  NULL,
    [ServiceInvoiceRecipient] NVARCHAR (256)	  NULL,
    [Created]               DATETIME         NULL DEFAULT CURRENT_TIMESTAMP,
    [Changed]               DATETIME         NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

GO

CREATE TRIGGER SERV_template_Trigger_Change_Log
ON
	dbo.SERV_template
	FOR UPDATE
	AS
		SET NOCOUNT ON
		IF NOT UPDATE([Changed])
		UPDATE SERV_template SET [Changed] = GETDATE() WHERE Id IN (SELECT Id FROM [inserted])

GO