/** 费用标准及业务事项改造表相关改动语句**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_STANDARD_TYPE' AND KSQL_COL_NAME ='FISPREAPPLY')
ALTER TABLE T_ER_STANDARD_TYPE ADD (FISPREAPPLY CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FSUMMARYCONTROL')
ALTER TABLE T_ER_FEE_STANDARD ADD (FSUMMARYCONTROL CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FACTUALREIMEXPENSE')
ALTER TABLE T_ER_FEE_STANDARD ADD (FACTUALREIMEXPENSE CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FMEETITEM')
ALTER TABLE T_ER_FEE_STANDARD ADD (FMEETITEM NVARCHAR(10) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FTREATTYPEBILL')
ALTER TABLE T_ER_FEE_STANDARD ADD (FTREATTYPEBILL NVARCHAR(10) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FMEETGRADEBILL')
ALTER TABLE T_ER_FEE_STANDARD ADD (FMEETGRADEBILL NVARCHAR(10) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_FEE_STANDARD' AND KSQL_COL_NAME ='FMEETTYPEBILL')
ALTER TABLE T_ER_FEE_STANDARD ADD (FMEETTYPEBILL NVARCHAR(10) DEFAULT ' ' NOT NULL );

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_RELATEDSTANDARD')
CREATE TABLE T_ER_RELATEDSTANDARD (
                                      FPKID BIGINT DEFAULT 0 NOT NULL,
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_STANDARD_SENSETIVE')
CREATE TABLE T_ER_STANDARD_SENSETIVE (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                         FSEQ INT DEFAULT 0 NOT NULL,
                                         FVERIFYFIELD NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FSENSETIVEFIELD NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FSENDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                         FVERIFYFLAG NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_STANDARD_ATTACH')
CREATE TABLE T_ER_STANDARD_ATTACH (
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                      FSEQ INT DEFAULT 0 NOT NULL,
                                      FATTACHNO NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                      FATTACHNAME NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                                      FATTDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


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

/**主键及索引相关改动**/
EXEC P_ALTERPK 'PK_T_ER_RELATEDSTANDARD', 'T_ER_RELATEDSTANDARD', 'FPKID', '1';

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

EXEC P_ALTERPK 'PK_T_ER_STANDARD_SENSETIVE', 'T_ER_STANDARD_SENSETIVE', 'FENTRYID', '1';

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

EXEC P_ALTERPK 'PK_T_ER_STANDARD_SENSETIVE_L', 'T_ER_STANDARD_SENSETIVE_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'INDEX_ER_STANDARD_SENSE_L') CREATE INDEX INDEX_ER_STANDARD_SENSE_L ON T_ER_STANDARD_SENSETIVE_L ( FENTRYID ,FLOCALEID );

EXEC P_ALTERPK 'PK_T_ER_STANDARD_ATTACH', 'T_ER_STANDARD_ATTACH', 'FENTRYID', '1';

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

EXEC P_ALTERPK 'PK_T_ER_STANDARD_ATTACH_L', 'T_ER_STANDARD_ATTACH_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'INDEX_ER_STANDARD_ATTACH_L_0') CREATE INDEX INDEX_ER_STANDARD_ATTACH_L_0 ON T_ER_STANDARD_ATTACH_L ( FENTRYID ,FLOCALEID );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_BILL_SETTING' AND KSQL_COL_NAME ='FISPRESET')
ALTER TABLE T_ER_BILL_SETTING ADD (FISPRESET CHAR(1) DEFAULT '0' NOT NULL );
