

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_BILLLK')
 CREATE TABLE T_CTBOTP_BILLLK (
FID BIGINT DEFAULT 0 NOT NULL,
FUNIQUEKEY VARCHAR(100) DEFAULT ' ' NOT NULL,
FSTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FTTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FTACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME DEFAULT GETDATE() NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_GSYNCLOG')
 CREATE TABLE T_CTBOTP_GSYNCLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FUNIQUEKEY VARCHAR(100) DEFAULT ' ' NOT NULL,
FSTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FTTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FTACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FRULEID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSYNCTYPE CHAR(1) DEFAULT '0' NOT NULL,
FUPDATETIME DATETIME,
FCREATETIME DATETIME DEFAULT GETDATE() NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_GSYNCLOG_C')
 CREATE TABLE T_CTBOTP_GSYNCLOG_C (
FID BIGINT DEFAULT 0 NOT NULL,
FRULENAME NVARCHAR(500) DEFAULT ' ' NOT NULL,
FSYNCCONTENT NVARCHAR(255),
FSYNCCONTENT_TAG NCLOB,
FDESC NVARCHAR(255),
FDESC_TAG NCLOB
);




IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_SYNCLOG')
 CREATE TABLE T_CTBOTP_SYNCLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FUNIQUEKEY NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FTTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FTACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FRULEID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSYNCTYPE CHAR(1) DEFAULT '0' NOT NULL,
FUPDATETIME DATETIME,
FCREATETIME DATETIME DEFAULT GETDATE() NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_SYNCLOG_C')
 CREATE TABLE T_CTBOTP_SYNCLOG_C (
FID BIGINT DEFAULT 0 NOT NULL,
FRULENAME NVARCHAR(500) DEFAULT ' ' NOT NULL,
FSYNCCONTENT NVARCHAR(255),
FSYNCCONTENT_TAG NCLOB,
FDESC NVARCHAR(255),
FDESC_TAG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_TSYNCLOG')
 CREATE TABLE T_CTBOTP_TSYNCLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FUNIQUEKEY NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FSACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FTTENANTCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FTACCOUNTID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTENTITYKEY VARCHAR(36) DEFAULT ' ' NOT NULL,
FTBILLID BIGINT DEFAULT 0 NOT NULL,
FSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FRULEID VARCHAR(50) DEFAULT ' ' NOT NULL,
FSYNCTYPE CHAR(1) DEFAULT '0' NOT NULL,
FUPDATETIME DATETIME,
FCREATETIME DATETIME DEFAULT GETDATE() NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTBOTP_TSYNCLOG_C')
 CREATE TABLE T_CTBOTP_TSYNCLOG_C (
FID BIGINT DEFAULT 0 NOT NULL,
FRULENAME NVARCHAR(500) DEFAULT ' ' NOT NULL,
FSYNCCONTENT NVARCHAR(255),
FSYNCCONTENT_TAG NCLOB,
FDESC NVARCHAR(255),
FDESC_TAG NCLOB
);

EXEC P_ALTERPK 'PK_T_CTBOTP_BILLLK', 'T_CTBOTP_BILLLK', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_BILLLK_SBILLID') CREATE INDEX IDX_CTBOTP_BILLLK_SBILLID ON T_CTBOTP_BILLLK ( FSBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_BILLLK_TBILLID') CREATE INDEX IDX_CTBOTP_BILLLK_TBILLID ON T_CTBOTP_BILLLK ( FTBILLID );

  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_BILLLK_UNIQUEKEY') CREATE INDEX IDX_CTBOTP_BILLLK_UNIQUEKEY ON T_CTBOTP_BILLLK ( FUNIQUEKEY );


 EXEC P_ALTERPK 'PK_T_CTBOTP_GSYNCLOG', 'T_CTBOTP_GSYNCLOG', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_GSYNCLOG_SBILLID') CREATE INDEX IDX_CTBOTP_GSYNCLOG_SBILLID ON T_CTBOTP_GSYNCLOG ( FSBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_GSYNCLOG_TBILLID') CREATE INDEX IDX_CTBOTP_GSYNCLOG_TBILLID ON T_CTBOTP_GSYNCLOG ( FTBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_GSYNCLOG_UNIQUEKEY') CREATE UNIQUE INDEX IDX_CTBOTP_GSYNCLOG_UNIQUEKEY ON T_CTBOTP_GSYNCLOG ( FUNIQUEKEY );



 EXEC P_ALTERPK 'PK_T_CTBOTP_SYNCLOG', 'T_CTBOTP_SYNCLOG', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_SSYNCLOG_SBILLID') CREATE INDEX IDX_CTBOTP_SSYNCLOG_SBILLID ON T_CTBOTP_SYNCLOG ( FSBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_SSYNCLOG_TBILLID') CREATE INDEX IDX_CTBOTP_SSYNCLOG_TBILLID ON T_CTBOTP_SYNCLOG ( FTBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_SSYNCLOG_UNIQUEKEY') CREATE UNIQUE INDEX IDX_CTBOTP_SSYNCLOG_UNIQUEKEY ON T_CTBOTP_SYNCLOG ( FUNIQUEKEY );



 EXEC P_ALTERPK 'PK_T_CTBOTP_TSYNCLOG', 'T_CTBOTP_TSYNCLOG', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_TSYNCLOG_SBILLID') CREATE INDEX IDX_CTBOTP_TSYNCLOG_SBILLID ON T_CTBOTP_TSYNCLOG ( FSBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_TSYNCLOG_TBILLID') CREATE INDEX IDX_CTBOTP_TSYNCLOG_TBILLID ON T_CTBOTP_TSYNCLOG ( FTBILLID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTBOTP_TSYNCLOG_UNIQUEKEY') CREATE UNIQUE INDEX IDX_CTBOTP_TSYNCLOG_UNIQUEKEY ON T_CTBOTP_TSYNCLOG ( FUNIQUEKEY );






