CREATE TABLE TBPMO_TEMPLATE
(
	GUID			INTEGER			NOT NULL	IDENTITY(1,1),
	NAME			VARCHAR(100)	NOT NULL	UNIQUE,
	TEMPLATE_PATH	VARCHAR(1000)	NOT NULL,
	DOCTYPE_ID		INTEGER			NOT NULL,
	ACTIVE			BIT				NOT NULL	DEFAULT 1,
	ADDED_WHO		VARCHAR(50)					DEFAULT 'Digital Data',
	ADDED_WHEN		DATETIME 					DEFAULT GETDATE(),
	CHANGED_WHO     VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBPMO_TEMPLATE			 PRIMARY KEY (GUID),
	CONSTRAINT		FK_TBPMO_TEMPLATE_DOCTYPE_ID FOREIGN KEY(DOCTYPE_ID)	REFERENCES TBDD_DOKUMENTART(GUID)
)
GO

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