/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AI_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FAH_EXT_DATA_ERR') 
 CREATE TABLE T_FAH_EXT_DATA_ERR (
FID BIGINT DEFAULT 0 NOT NULL,
FDATAID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FFIELDID BIGINT DEFAULT 0 NOT NULL,
FVALUE VARCHAR(200),
FMSG NCLOB DEFAULT ' ',
FCREATETIME DATETIME,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FAH_EXT_MODFLDGRP') 
 CREATE TABLE T_FAH_EXT_MODFLDGRP (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FGROUPTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FGROUPNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FGROUPNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
FTABLENAME VARCHAR(30) DEFAULT ' ' NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER VARCHAR(62) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FAH_EXT_MODFLDS') 
 CREATE TABLE T_FAH_EXT_MODFLDS (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FNAME VARCHAR(100) DEFAULT ' ' NOT NULL,
FNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FBASEPROP VARCHAR(36) DEFAULT ' ' NOT NULL,
FASSISTPROP BIGINT DEFAULT 0 NOT NULL,
FDATATYPE VARCHAR(2) DEFAULT ' ' NOT NULL,
FVISABLE CHAR(1) DEFAULT ' ' NOT NULL,
FREQUIRED CHAR(1) DEFAULT ' ' NOT NULL,
FREQUIREDCONDITION NCLOB,
FPROPERTIES_TAG NCLOB
);


 EXEC p_AlterColumn 'T_AI_EVENT', 'FDATA', 'CHAR(1)', 'NOT NULL', '1111', ''' ''';

 EXEC p_AlterColumn 'T_AI_EVENT', 'FTEXTAREAFIELD', 'CHAR(1)', 'NOT NULL', '1111', ''' ''';

 EXEC p_AlterColumn 'T_AI_EVENT', 'FPAGING', 'CHAR(1)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENT' AND KSQL_COL_NAME ='FVERSIONNUM') 
 ALTER TABLE T_AI_EVENT ADD (FVERSIONNUM INT DEFAULT 1 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FDESCRIPTION') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FDESCRIPTION VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FAPPVERSION') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FAPPVERSION CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FREFDATACNT') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FREFDATACNT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FVERSIONNUM') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FVERSIONNUM INT DEFAULT 1 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FLATESTVERSION') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FLATESTVERSION CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FENABLEDBY') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FENABLEDBY BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FDISABLEDBY') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FDISABLEDBY BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FENABLEDTIME') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FENABLEDTIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AI_EVENTCLASS' AND KSQL_COL_NAME ='FDISABLEDTIME') 
 ALTER TABLE T_AI_EVENTCLASS ADD (FDISABLEDTIME DATETIME );

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