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

Create Table T_EQP_RELATION(
RuleId		VARCHAR(50)		NOT NULL,
EqpId		VARCHAR(20),
Flag		DECIMAL(1)		NOT NULL,
EqpId2		VARCHAR(20),
Flag2		DECIMAL(1)		NOT NULL,
EqpId3		VARCHAR(20),
Flag3		DECIMAL(1)		NOT NULL,
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_EQP_RELATION PRIMARY KEY (RuleId)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_EQP_RELATION ALTER COLUMN RuleId SET WITH Default '-1'@
Alter Table T_EQP_RELATION ALTER COLUMN EqpId SET WITH Default '-1'@
Alter Table T_EQP_RELATION ALTER COLUMN Flag SET WITH Default 1@
Alter Table T_EQP_RELATION ALTER COLUMN Flag2 SET WITH Default 0@
Alter Table T_EQP_RELATION ALTER COLUMN Flag3 SET WITH Default 0@

COMMENT ON Table T_EQP_RELATION IS '设备九位码关系表'@

COMMENT ON T_EQP_RELATION (RuleId IS '规则id')@
COMMENT ON T_EQP_RELATION (EqpId IS '设备id')@
COMMENT ON T_EQP_RELATION (Flag IS '是否转发')@
COMMENT ON T_EQP_RELATION (EqpId2 IS '设备id2')@
COMMENT ON T_EQP_RELATION (Flag2 IS '是否转发2')@
COMMENT ON T_EQP_RELATION (EqpId3 IS '设备id3')@
COMMENT ON T_EQP_RELATION (Flag3 IS '是否转发3')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_EQP_RELATION
*****************************************************************************/
DROP TRIGGER ins_b_T_EQP_RELATION@

CREATE OR REPLACE TRIGGER ins_b_T_EQP_RELATION
BEFORE INSERT ON T_EQP_RELATION 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_RELATION
*****************************************************************************/
DROP TRIGGER upd_b_T_EQP_RELATION@

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