IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_BIZ_INFO' AND KSQL_COL_NAME IN ('FSYNCAPPLYBILLTYPE'))
ALTER TABLE T_ER_BIZ_INFO ADD (FSYNCAPPLYBILLTYPE CHAR(1) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_SYNCAPPLYBILLTYPE')
CREATE TABLE T_ER_SYNCAPPLYBILLTYPE (
                                        FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                        FID BIGINT DEFAULT 0 NOT NULL,
                                        FSEQ INT DEFAULT 0 NOT NULL,
                                        FBOOKPRODUCTS VARCHAR(50) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_SYNCAPPLYBILLTYPE', 'T_ER_SYNCAPPLYBILLTYPE', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_SEQ_FID') CREATE INDEX IDX_ER_SEQ_FID ON T_ER_SYNCAPPLYBILLTYPE ( FID ,FSEQ );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_SYNCAPPLYBIIORG')
CREATE TABLE T_ER_SYNCAPPLYBIIORG (
                                      FPKID BIGINT DEFAULT 0 NOT NULL,
                                      FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                      FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_SYNCAPPLYBIIORG', 'T_ER_SYNCAPPLYBIIORG', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_ENTRYID_BASEDATAID') CREATE INDEX IDX_ER_ENTRYID_BASEDATAID ON T_ER_SYNCAPPLYBIIORG ( FENTRYID ,FBASEDATAID );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYBILLTYPE')
CREATE TABLE T_ER_APPLYBILLTYPE (
                                    FPKID BIGINT DEFAULT 0 NOT NULL,
                                    FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                    FBASEDATAID VARCHAR(255) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_APPLYBILLTYPE', 'T_ER_APPLYBILLTYPE', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ENTRYID_BASEDATAID') CREATE INDEX IDX_ENTRYID_BASEDATAID ON T_ER_APPLYBILLTYPE ( FENTRYID ,FBASEDATAID );