/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\GL_table.sql **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENT') 
 CREATE TABLE T_AI_EVENT (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FDESCRIPTION NVARCHAR(500) DEFAULT ' ' NOT NULL,
FEVENTCLASS BIGINT DEFAULT 0 NOT NULL,
FSOURCESYS VARCHAR(30) DEFAULT ' ' NOT NULL,
FDATA NVARCHAR(500) DEFAULT ' ' NOT NULL,
FDATA_TAG NCLOB,
FEVENTID VARCHAR(100) DEFAULT ' ' NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL,
FTEXTAREAFIELD NVARCHAR(30) DEFAULT ' ' NOT NULL,
FPAGING NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENTRYCOUNT INT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENT_EN') 
 CREATE TABLE T_AI_EVENT_EN (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FENTRYDATA NVARCHAR(510) DEFAULT ' ' NOT NULL,
FENTRYDATA_TAG NCLOB,
FEVENTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENT_INDEX') 
 CREATE TABLE T_AI_EVENT_INDEX (
FID BIGINT DEFAULT 0 NOT NULL,
FEVENTID BIGINT DEFAULT 0 NOT NULL,
FFIELDNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FFIELDVALUE NVARCHAR(80) DEFAULT ' ' NOT NULL,
FEVENTCLASSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTBLOCK') 
 CREATE TABLE T_AI_EVENTBLOCK (
FID BIGINT DEFAULT 0 NOT NULL,
FEVENTCLASS BIGINT DEFAULT 0 NOT NULL,
FTEXTFIELD NVARCHAR(100) DEFAULT ' ' NOT NULL,
FEVENTID BIGINT DEFAULT 0 NOT NULL,
FFIELDVALUE NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFIELDNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTCLASS') 
 CREATE TABLE T_AI_EVENTCLASS (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FEVTBILL BIGINT DEFAULT 0 NOT NULL,
FEVTACTION VARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTCLASS_L') 
 CREATE TABLE T_AI_EVENTCLASS_L (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTCONSUMER') 
 CREATE TABLE T_AI_EVENTCONSUMER (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FADMIN BIGINT DEFAULT 0 NOT NULL,
FEVENTCLASS BIGINT DEFAULT 0 NOT NULL,
FACTION VARCHAR(500) DEFAULT ' ' NOT NULL,
FTEXTFIELD NVARCHAR(500) DEFAULT ' ' NOT NULL,
FCONDITION VARCHAR(500) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTCONSUMER_L') 
 CREATE TABLE T_AI_EVENTCONSUMER_L (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTENTRY_L') 
 CREATE TABLE T_AI_EVENTENTRY_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENFDDISPLAYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTFIELDS_L') 
 CREATE TABLE T_AI_EVENTFIELDS_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDISPLAYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTGROUP') 
 CREATE TABLE T_AI_EVENTGROUP (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFULLNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '0' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT ' ' NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTGROUP_ASSIGN') 
 CREATE TABLE T_AI_EVENTGROUP_ASSIGN (
FID BIGINT DEFAULT 0 NOT NULL,
FEVENTGROUPID BIGINT DEFAULT 0 NOT NULL,
FAPPID VARCHAR(36) DEFAULT ' ' NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTGROUP_L') 
 CREATE TABLE T_AI_EVENTGROUP_L (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFULLNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_PREEVENT') 
 CREATE TABLE T_AI_PREEVENT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPREEVENTCLASS BIGINT DEFAULT 0 NOT NULL,
FPREEVTFIELD NVARCHAR(80) DEFAULT ' ' NOT NULL,
FEVTFIELD NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPRESTATUS CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTENTRY') 
 CREATE TABLE T_AI_EVENTENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYFIELDNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYREFOBJ NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYFIELDTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FENTRYISMUSTINPUT CHAR(1) DEFAULT ' ' NOT NULL,
FENTRYASSISTANT BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AI_EVENTFIELDS') 
 CREATE TABLE T_AI_EVENTFIELDS (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FDISPLAYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFIELDNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FREFOBJ NVARCHAR(36) DEFAULT ' ' NOT NULL,
FFIELDTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FEVENTCLASS BIGINT DEFAULT 0 NOT NULL,
FISMUSTINPUT CHAR(1) DEFAULT ' ' NOT NULL,
FASSISTANT BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_DAPCONFIG' AND KSQL_COL_NAME ='FEVENTCLASSID') 
 ALTER TABLE T_AI_DAPCONFIG ADD (FEVENTCLASSID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_VCHTEMPLATE' AND KSQL_COL_NAME ='FEVENTCLASSID') 
 ALTER TABLE T_AI_VCHTEMPLATE ADD (FEVENTCLASSID BIGINT DEFAULT 0 NOT NULL );

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\GL_table.sql **/
