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

GO
CREATE TABLE [dbo].[AGNT_template] (
    [Id]                   UNIQUEIDENTIFIER NOT NULL,
    [Title]                NVARCHAR (50)    NULL,
    [AgentCompanyName]     NVARCHAR (100)   NULL,
    [AgentStreetAndNumber] NVARCHAR (100)   NULL,
    [AgentPostalCode]      NVARCHAR (25)    NULL,
    [AgentCity]            NVARCHAR (100)   NULL,
    [AgentCountry]         NVARCHAR (100)   NULL,
    [AgentLastName]        NVARCHAR (100)   NULL,
    [AgentFirstName]       NVARCHAR (100)   NULL,
    [AgentPhone]           NVARCHAR (100)   NULL,
    [AgentFax]             NVARCHAR (100)   NULL,
    [AgentEMail]           NVARCHAR (100)   NULL,
    [Created]              DATETIME         NULL DEFAULT CURRENT_TIMESTAMP,
    [Changed]              DATETIME         NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

GO

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