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

Create Table T_SAMPLE_MAG(
SampleId		VARCHAR(50)		NOT NULL,
RuleId		VARCHAR(50)		NOT NULL,
StartTime		TIMESTAMP		NOT NULL,
EndTime		TIMESTAMP		NOT NULL,
Usable		DECIMAL(4)		NOT NULL,
Result		VARCHAR(500),
Type		VARCHAR(36)		NOT NULL,
Verify		DECIMAL(1),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_SAMPLE_MAG PRIMARY KEY (SampleId, RuleId)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_SAMPLE_MAG ALTER COLUMN Usable SET WITH Default 0@
Alter Table T_SAMPLE_MAG ALTER COLUMN Verify SET WITH Default 0@

COMMENT ON Table T_SAMPLE_MAG IS '样本管理表'@

COMMENT ON T_SAMPLE_MAG (SampleId IS '样本ID')@
COMMENT ON T_SAMPLE_MAG (RuleId IS '规则id')@
COMMENT ON T_SAMPLE_MAG (StartTime IS '样本制作的开始时间')@
COMMENT ON T_SAMPLE_MAG (EndTime IS '样本制作的结束时间')@
COMMENT ON T_SAMPLE_MAG (Usable IS '样本有效性')@
COMMENT ON T_SAMPLE_MAG (Result IS '样本结果')@
COMMENT ON T_SAMPLE_MAG (Type IS '样本类型')@
COMMENT ON T_SAMPLE_MAG (Verify IS '样本确认')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_SAMPLE_MAG
*****************************************************************************/
DROP TRIGGER ins_b_T_SAMPLE_MAG@

CREATE OR REPLACE TRIGGER ins_b_T_SAMPLE_MAG
BEFORE INSERT ON T_SAMPLE_MAG 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_MAG
*****************************************************************************/
DROP TRIGGER upd_b_T_SAMPLE_MAG@

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