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

Create Table T_STA_RULE_POLIFIT(
RULEID		VARCHAR(50)		NOT NULL,
SAMPLE_DATE		TIMESTAMP		NOT NULL,
FLAG		VARCHAR(50),
X1		DECIMAL(5),
X2		DECIMAL(5),
Y		DECIMAL(13,3),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_STA_RULE_POLIFIT PRIMARY KEY (RULEID, SAMPLE_DATE)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_STA_RULE_POLIFIT ALTER COLUMN X1 SET WITH Default 0@
Alter Table T_STA_RULE_POLIFIT ALTER COLUMN X2 SET WITH Default 1@

COMMENT ON Table T_STA_RULE_POLIFIT IS '拟合样本数据表'@

COMMENT ON T_STA_RULE_POLIFIT (RULEID IS '规则id')@
COMMENT ON T_STA_RULE_POLIFIT (SAMPLE_DATE IS '记录时间')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_STA_RULE_POLIFIT
*****************************************************************************/
DROP TRIGGER ins_b_T_STA_RULE_POLIFIT@

CREATE OR REPLACE TRIGGER ins_b_T_STA_RULE_POLIFIT
BEFORE INSERT ON T_STA_RULE_POLIFIT 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_STA_RULE_POLIFIT
*****************************************************************************/
DROP TRIGGER upd_b_T_STA_RULE_POLIFIT@

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