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

Create Table T_DAT_DICT(
Name		VARCHAR(80)		NOT NULL,
Chinese		VARCHAR(100),
Group		VARCHAR(80),
DataType		VARCHAR(10),
Unit		VARCHAR(10),
DataAddress		VARCHAR(100),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_DAT_DICT PRIMARY KEY (Name)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_DAT_DICT IS '数据字典'@

COMMENT ON T_DAT_DICT (Name IS '名称')@
COMMENT ON T_DAT_DICT (Chinese IS '中文名称')@
COMMENT ON T_DAT_DICT (Group IS '数据分组')@
COMMENT ON T_DAT_DICT (DataType IS '数据类型')@
COMMENT ON T_DAT_DICT (Unit IS 'unit of the value')@
COMMENT ON T_DAT_DICT (DataAddress IS 'the address of data')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_DAT_DICT
*****************************************************************************/
DROP TRIGGER ins_b_T_DAT_DICT@

CREATE OR REPLACE TRIGGER ins_b_T_DAT_DICT
BEFORE INSERT ON T_DAT_DICT 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_DAT_DICT
*****************************************************************************/
DROP TRIGGER upd_b_T_DAT_DICT@

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