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

Create Table T_EQP_DATA(
EqpId		VARCHAR(20)		NOT NULL,
EqpType		VARCHAR(40),
EqpName		VARCHAR(80),
Factory		VARCHAR(20),
UnitNo		VARCHAR(60),
DateIn		TIMESTAMP,
DateOn		TIMESTAMP,
DateOff		TIMESTAMP,
Tags		VARCHAR(200),
Zone		VARCHAR(30),
Flag		VARCHAR(1),
Operator		VARCHAR(80),
FileAddr		VARCHAR(100),
RuleType		DECIMAL(5),
Value		DECIMAL(13,3),
Unit		VARCHAR(20),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_EQP_DATA PRIMARY KEY (EqpId)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_EQP_DATA ALTER COLUMN Flag SET WITH Default '1'@
Alter Table T_EQP_DATA ALTER COLUMN RuleType SET WITH Default 0@
Alter Table T_EQP_DATA ALTER COLUMN Value SET WITH Default 0@

COMMENT ON Table T_EQP_DATA IS '设备信息'@

COMMENT ON T_EQP_DATA (EqpId IS '设备编号')@
COMMENT ON T_EQP_DATA (EqpType IS '设备型号')@
COMMENT ON T_EQP_DATA (EqpName IS '设备名称')@
COMMENT ON T_EQP_DATA (Factory IS '设备厂家')@
COMMENT ON T_EQP_DATA (UnitNo IS '机组号')@
COMMENT ON T_EQP_DATA (DateIn IS '入库时间')@
COMMENT ON T_EQP_DATA (DateOn IS '上线时间')@
COMMENT ON T_EQP_DATA (DateOff IS '下线时间')@
COMMENT ON T_EQP_DATA (Tags IS '标签')@
COMMENT ON T_EQP_DATA (Zone IS '设备安装区')@
COMMENT ON T_EQP_DATA (Flag IS '有效性')@
COMMENT ON T_EQP_DATA (Operator IS '责任人')@
COMMENT ON T_EQP_DATA (FileAddr IS '文件索引')@
COMMENT ON T_EQP_DATA (RuleType IS '规则类型 0：无 1：按重量 2：按长度 3：按时间')@
COMMENT ON T_EQP_DATA (Value IS '数值')@
COMMENT ON T_EQP_DATA (Unit IS '单位')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_EQP_DATA
*****************************************************************************/
DROP TRIGGER ins_b_T_EQP_DATA@

CREATE OR REPLACE TRIGGER ins_b_T_EQP_DATA
BEFORE INSERT ON T_EQP_DATA 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_DATA
*****************************************************************************/
DROP TRIGGER upd_b_T_EQP_DATA@

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