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

Create Table T_SAMPLE_RECORD(
RuleId		VARCHAR(50)		NOT NULL,
Result		VARCHAR(500)		NOT NULL,
SEQ		DECIMAL(4)		NOT NULL,
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_SAMPLE_RECORD PRIMARY KEY (RuleId, SEQ)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_SAMPLE_RECORD IS '自动统计样本历史记录表'@

COMMENT ON T_SAMPLE_RECORD (RuleId IS '规则id')@
COMMENT ON T_SAMPLE_RECORD (Result IS '样本结果')@
COMMENT ON T_SAMPLE_RECORD (SEQ IS '样本序号，用于更新，每个规则只记录最多30条记录')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_SAMPLE_RECORD
*****************************************************************************/
DROP TRIGGER ins_b_T_SAMPLE_RECORD@

CREATE OR REPLACE TRIGGER ins_b_T_SAMPLE_RECORD
BEFORE INSERT ON T_SAMPLE_RECORD 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_SAMPLE_RECORD
*****************************************************************************/
DROP TRIGGER upd_b_T_SAMPLE_RECORD@

CREATE OR REPLACE TRIGGER upd_b_T_SAMPLE_RECORD
BEFORE UPDATE ON T_SAMPLE_RECORD 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
@
