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

Create Table T_RULE_SAMPLE_2D(
RuleId		VARCHAR(50)		NOT NULL,
X1		DECIMAL(8,2)		NOT NULL,
X2		DECIMAL(8,2)		NOT NULL,
Flag		DECIMAL(4),
Count		DECIMAL(8),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_RULE_SAMPLE_2D PRIMARY KEY (RuleId, X1, X2)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_RULE_SAMPLE_2D IS '2维统计样本表'@

COMMENT ON T_RULE_SAMPLE_2D (RuleId IS '规则id')@
COMMENT ON T_RULE_SAMPLE_2D (X1 IS '样本值')@
COMMENT ON T_RULE_SAMPLE_2D (X2 IS '样本值')@
COMMENT ON T_RULE_SAMPLE_2D (Flag IS '是否有效')@
COMMENT ON T_RULE_SAMPLE_2D (Count IS '统计的频次')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_RULE_SAMPLE_2D
*****************************************************************************/
DROP TRIGGER ins_b_T_RULE_SAMPLE_2D@

CREATE OR REPLACE TRIGGER ins_b_T_RULE_SAMPLE_2D
BEFORE INSERT ON T_RULE_SAMPLE_2D 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_RULE_SAMPLE_2D
*****************************************************************************/
DROP TRIGGER upd_b_T_RULE_SAMPLE_2D@

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