CREATE TABLE TBPMO_RUN_PROCEDURES
(
	GUID			INTEGER			NOT NULL	IDENTITY(1,1),
	FORM_ID			INTEGER			NOT NULL,
	EXECUTE_COMMAND	VARCHAR(500)	NOT NULL,
	ADDED_WHO		VARCHAR(50)		NOT NULL	DEFAULT 'Digital Data',
	ADDED_WHEN		DATETIME 		NOT NULL	DEFAULT GETDATE(),
	CHANGED_WHO     VARCHAR(50),
	CHANGED_WHEN	DATETIME,
	CONSTRAINT		PK_TBPMO_RUN_PROCEDURES				PRIMARY KEY (GUID),
	CONSTRAINT		FK_TBPMO_RUN_PROCEDURES_FORM_ID		FOREIGN KEY (FORM_ID)  REFERENCES  TBPMO_FORM (GUID),
)
GO

CREATE TRIGGER TBPMO_RUN_PROCEDURES_AFT_UPD ON TBPMO_RUN_PROCEDURES
FOR UPDATE
AS
	UPDATE TBPMO_RUN_PROCEDURES SET CHANGED_WHEN = GETDATE() FROM INSERTED WHERE TBPMO_RUN_PROCEDURES.GUID = INSERTED.GUID
GO
INSERT INTO TBPMO_RUN_PROCEDURES(FORM_ID,EXECUTE_COMMAND) 
VALUES 
	(2,'EXEC PRPMO_AFTER_UPDATE_VALUES @FORM_ID,@RECORD_ID')
GO
