-- Version:		2025.7.31  14:52:27
Drop Table T_HMI_TEMPLATE@

Create Table T_HMI_TEMPLATE(
name		VARCHAR(80)		NOT NULL,
ruleid		VARCHAR(36),
tname		VARCHAR(50),
items		VARCHAR(200),
statItems		VARCHAR(200),
operator		VARCHAR(80),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_HMI_TEMPLATE PRIMARY KEY (name)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_HMI_TEMPLATE IS '设备可视化模板'@

COMMENT ON T_HMI_TEMPLATE (name IS '设备九位码')@
COMMENT ON T_HMI_TEMPLATE (ruleid IS '规则id')@
COMMENT ON T_HMI_TEMPLATE (tname IS '模板名')@
COMMENT ON T_HMI_TEMPLATE (items IS 'item项')@
COMMENT ON T_HMI_TEMPLATE (statItems IS '统计项')@
COMMENT ON T_HMI_TEMPLATE (operator IS '责任人')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_HMI_TEMPLATE
*****************************************************************************/
DROP TRIGGER ins_b_T_HMI_TEMPLATE@

CREATE OR REPLACE TRIGGER ins_b_T_HMI_TEMPLATE
BEFORE INSERT ON T_HMI_TEMPLATE REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.toc = (values sysdate);
	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
/****************************************************************************
						UPDATE TRIGGER FOR TABLE
							  T_HMI_TEMPLATE
*****************************************************************************/
DROP TRIGGER upd_b_T_HMI_TEMPLATE@

CREATE OR REPLACE TRIGGER upd_b_T_HMI_TEMPLATE
BEFORE UPDATE ON T_HMI_TEMPLATE REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
