CREATE TABLE TBPMO_TEMPLATE_PATTERN
(
	GUID			INTEGER			NOT NULL	IDENTITY(1,1),
	TEMPLATE_ID		INTEGER			NOT NULL,
	NAME_PATTERN	VARCHAR(100)	NOT NULL,
	FIXED_VALUE		VARCHAR(100),
	CONNECTION_ID	INTEGER,
	SQL_COMMAND		VARCHAR(2000),
	ADDED_WHO		VARCHAR(50)					DEFAULT 'Digital Data',
	ADDED_WHEN		DATETIME 					DEFAULT GETDATE(),
	CHANGED_WHO     VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBPMO_TEMPLATE_PATTERN				PRIMARY KEY (GUID),
	CONSTRAINT		FK_TBPMO_TEMPLATE_PATTERN_TEMPLATE_ID	FOREIGN KEY(TEMPLATE_ID)	REFERENCES TBPMO_TEMPLATE(GUID),
	CONSTRAINT		UQ_TBPMO_TEMPLATE_PATTERN				UNIQUE (TEMPLATE_ID, NAME_PATTERN)
)
GO

CREATE TRIGGER TBPMO_TEMPLATE_PATTERN_AFT_UPD ON TBPMO_TEMPLATE_PATTERN
FOR UPDATE
AS
	UPDATE TBPMO_TEMPLATE_PATTERN SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBPMO_TEMPLATE_PATTERN.GUID = INSERTED.GUID
GO