IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CASWRITEBACK')
CREATE TABLE T_ER_CASWRITEBACK (
FID BIGINT DEFAULT 0 NOT NULL,
FOPERATETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FBILLTYPE  VARCHAR(50) DEFAULT ' ' NOT NULL,
FTARGETBILLID BIGINT DEFAULT 0 NOT NULL,
FTARGETENTRYID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME
);

EXEC P_ALTERPK 'PK_ER_CASWRITEBACK', 'T_ER_CASWRITEBACK', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'INDEX_ER_WRITEBACK_BILLID')
CREATE INDEX INDEX_ER_WRITEBACK_BILLID ON T_ER_CASWRITEBACK ( FTARGETBILLID );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CASWRITEBACK_LOG')
CREATE TABLE T_ER_CASWRITEBACK_LOG (
FID BIGINT DEFAULT 0 NOT NULL,
FOPERATETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FBILLTYPE  VARCHAR(50) DEFAULT ' ' NOT NULL,
FREQUESTPARAM NCLOB,
FREQUESTPARAM_TAG NCLOB
);

EXEC P_ALTERPK 'PK_ER_CASWRITEBACK_LOG', 'T_ER_CASWRITEBACK_LOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'INDEX_ER_WRITEBACK_BILLTYPE')
CREATE INDEX INDEX_ER_WRITEBACK_BILLTYPE ON T_ER_CASWRITEBACK_LOG ( FBILLTYPE );