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

Create Table T_EQP_REPAIR(
EqpId		VARCHAR(20)		NOT NULL,
RepairDate		TIMESTAMP,
RepairPlan		TIMESTAMP,
Data		DECIMAL(10),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_EQP_REPAIR PRIMARY KEY (EqpId)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_EQP_REPAIR ALTER COLUMN Data SET WITH Default 0@

COMMENT ON Table T_EQP_REPAIR IS '设备检修计划'@

COMMENT ON T_EQP_REPAIR (EqpId IS '设备编号')@
COMMENT ON T_EQP_REPAIR (RepairDate IS '检修时间')@
COMMENT ON T_EQP_REPAIR (RepairPlan IS '检修计划')@
COMMENT ON T_EQP_REPAIR (Data IS '实绩数据，累积长度或重量')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_EQP_REPAIR
*****************************************************************************/
DROP TRIGGER ins_b_T_EQP_REPAIR@

CREATE OR REPLACE TRIGGER ins_b_T_EQP_REPAIR
BEFORE INSERT ON T_EQP_REPAIR 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_EQP_REPAIR
*****************************************************************************/
DROP TRIGGER upd_b_T_EQP_REPAIR@

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