/**Begin D:\PDM\pdm_upgrade\pdm1\ER_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_FIELDMAPPING')
CREATE TABLE T_ER_TRIP_FIELDMAPPING (
                                        FID BIGINT DEFAULT 0 NOT NULL,
                                        FNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
                                        FNAME NVARCHAR(30) DEFAULT ' ' NOT NULL,
                                        FSTATUS VARCHAR(30) DEFAULT '1' NOT NULL,
                                        FENABLE CHAR(1) DEFAULT '1' NOT NULL,
                                        FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                        FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                        FCREATETIME DATETIME,
                                        FMODIFYTIME DATETIME,
                                        FMASTERID BIGINT DEFAULT 0 NOT NULL,
                                        FSERVER BIGINT DEFAULT 0 NOT NULL,
                                        FPORTTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
                                        FFUNCTION VARCHAR(50) DEFAULT ' ' NOT NULL,
                                        FURL VARCHAR(255) DEFAULT ' ' NOT NULL,
                                        FPARAMSJSON NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                        FPARAMSJSON_TAG NCLOB DEFAULT ' ',
                                        FDATAJSON NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                        FCLASSFORNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                        FDATAJSON_TAG NCLOB DEFAULT ' ',
                                        FISDEFAULT VARCHAR(2) DEFAULT '0' NOT NULL,
                                        FSYNCTYPE VARCHAR(10) DEFAULT ' ' NOT NULL,
                                        FMETHOD VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_QUERYENTRY')
CREATE TABLE T_ER_TRIP_QUERYENTRY (
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FSEQ BIGINT DEFAULT 0 NOT NULL,
                                      FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                      FQUERYLEFTBRACKET VARCHAR(10) DEFAULT ' ' NOT NULL,
                                      FQUERYFIELD VARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FQUERYCONDITION VARCHAR(30) DEFAULT ' ' NOT NULL,
                                      FQUERYVALUE NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FQUERYPLUGINVALUE VARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FQUERYPLUGINVALUEEXT VARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FQUERYRIGHTBRACKET VARCHAR(10) DEFAULT ' ' NOT NULL,
                                      FQUERYLOGIC VARCHAR(10) DEFAULT ' ' NOT NULL,
                                      FQUERYISDEFAULT VARCHAR(10) DEFAULT '0' NOT NULL,
                                      FQUERYSTATUS VARCHAR(10) DEFAULT '1' NOT NULL,
                                      FQUERYDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                      FQUERYCREATETIME DATETIME,
                                      FQUERYMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_FILTERENTRY')
CREATE TABLE T_ER_TRIP_FILTERENTRY (
                                       FID BIGINT DEFAULT 0 NOT NULL,
                                       FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                       FSEQ BIGINT DEFAULT 0 NOT NULL,
                                       FFILTERLEFTBRACKET VARCHAR(10) DEFAULT ' ' NOT NULL,
                                       FFILTERFIELD VARCHAR(255) DEFAULT ' ' NOT NULL,
                                       FFILTERCONDITION VARCHAR(10) DEFAULT ' ' NOT NULL,
                                       FFILTERVALUE NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                       FFILTERRIGHTBRACKET VARCHAR(10) DEFAULT ' ' NOT NULL,
                                       FFILTERLOGIC VARCHAR(10) DEFAULT ' ' NOT NULL,
                                       FFILTERISDEFAULT VARCHAR(10) DEFAULT '0' NOT NULL,
                                       FFILTERSTATUS VARCHAR(10) DEFAULT '1' NOT NULL,
                                       FFILTERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                       FFILTERCREATETIME DATETIME,
                                       FFILTERMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_IGNOREEXENTRY')
CREATE TABLE T_ER_TRIP_IGNOREEXENTRY (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FSEQ BIGINT DEFAULT 0 NOT NULL,
                                         FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                         FEXNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FEXFIELD VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FEXDESC NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FEXISDEFAULT VARCHAR(10) DEFAULT '0' NOT NULL,
                                         FEXSTATUS VARCHAR(10) DEFAULT '1' NOT NULL,
                                         FEXCREATETIME DATETIME,
                                         FEXMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_FIELDMAPENTRY')
CREATE TABLE T_ER_TRIP_FIELDMAPENTRY (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FSEQ BIGINT DEFAULT 0 NOT NULL,
                                         FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                         FMAPTARGETFIELD VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FMAPTARGETFIELDDESC NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FMAPSOURCEFIELD VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FMAPTYPE VARCHAR(10) DEFAULT ' ' NOT NULL,
                                         FMAPDESIGN VARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FMAPSOURCEFIELDEXT VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FMAPTYPEEXT VARCHAR(10) DEFAULT ' ' NOT NULL,
                                         FMAPDESIGNEXT VARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FMAPPRIMARYKEY VARCHAR(10) DEFAULT '0' NOT NULL,
                                         FMAPISDEFAULT VARCHAR(10) DEFAULT '0' NOT NULL,
                                         FMAPSTATUS VARCHAR(10) DEFAULT '1' NOT NULL,
                                         FMAPDESC NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FMAPCREATETIME DATETIME,
                                         FMAPMODIFYTIME DATETIME
);


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


/**End D:\PDM\pdm_upgrade\pdm1\ER_table.sql **/


/**Begin D:\PDM\pdm_upgrade\pdm1\ER_constraint.sql **/
EXEC P_ALTERPK 'PK_T_ER_TRIP_FIELDMAPPING', 'T_ER_TRIP_FIELDMAPPING', 'FID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'UQ_FIELDMAPPING_FNUMBER') CREATE UNIQUE INDEX UQ_FIELDMAPPING_FNUMBER ON T_ER_TRIP_FIELDMAPPING ( FNUMBER );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FIELDMAPPING_FSERVICE') CREATE  CLUSTERED INDEX IDX_FIELDMAPPING_FSERVICE ON T_ER_TRIP_FIELDMAPPING ( FSERVER );


EXEC P_ALTERPK 'PK_T_ER_TRIP_QUERYENTRY', 'T_ER_TRIP_QUERYENTRY', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_QUERYENTRY_FID') CREATE  CLUSTERED INDEX IDX_QUERYENTRY_FID ON T_ER_TRIP_QUERYENTRY ( FID );


EXEC P_ALTERPK 'PK_T_ER_TRIP_FILTERENTRY', 'T_ER_TRIP_FILTERENTRY', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FILTERENTRY_FID') CREATE  CLUSTERED INDEX IDX_FILTERENTRY_FID ON T_ER_TRIP_FILTERENTRY ( FID );


EXEC P_ALTERPK 'PK_T_ER_TRIP_IGNOREEXENTRY', 'T_ER_TRIP_IGNOREEXENTRY', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IGNOREEXENTRY_FID') CREATE INDEX IDX_IGNOREEXENTRY_FID ON T_ER_TRIP_IGNOREEXENTRY ( FID );


EXEC P_ALTERPK 'PK_T_ER_TRIP_FIELDMAPENTRY', 'T_ER_TRIP_FIELDMAPENTRY', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FME_FID') CREATE  CLUSTERED INDEX IDX_FME_FID ON T_ER_TRIP_FIELDMAPENTRY ( FID );


EXEC P_ALTERPK 'PK_T_ER_TRIP_FIELDMAPPING_L', 'T_ER_TRIP_FIELDMAPPING_L', 'FPKID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FML_FIDFLOCALID') CREATE  CLUSTERED INDEX IDX_FML_FIDFLOCALID ON T_ER_TRIP_FIELDMAPPING_L ( FID ,FLOCALEID );



/**End D:\PDM\pdm_upgrade\pdm1\ER_constraint.sql **/

