IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTSY_CTRLSTRATEGY_SYNC') 
 CREATE TABLE T_CTSY_CTRLSTRATEGY_SYNC (
FID BIGINT DEFAULT 0 NOT NULL,
FUID VARCHAR(50) DEFAULT ' ' NOT NULL,
FMSGID VARCHAR(50) DEFAULT ' ' NOT NULL,
FOPTYPE CHAR(1) DEFAULT '0' NOT NULL,
FTARTENANTNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
FSYNCSTATUS CHAR(1) DEFAULT '0' NOT NULL,
FOPORGID BIGINT DEFAULT 0 NOT NULL,
FENTITYID VARCHAR(50) DEFAULT ' ' NOT NULL,
FREMARK VARCHAR(255) DEFAULT ' ' NOT NULL,
FAPPID VARCHAR(50) DEFAULT ' ' NOT NULL,
FTRACEID VARCHAR(255) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTSY_CTRL_SYNC_DATA') 
 CREATE TABLE T_CTSY_CTRL_SYNC_DATA (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FERRORMSG VARCHAR(255) DEFAULT ' ' NOT NULL,
FDATAID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CTSY_CTRL_SYNC_ORG') 
 CREATE TABLE T_CTSY_CTRL_SYNC_ORG (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FERRORMSG VARCHAR(255) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FORGNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL
);



EXEC P_ALTERPK 'PK_T_CTSY_CTRLSTRATEGY_SYNC', 'T_CTSY_CTRLSTRATEGY_SYNC', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_CTSY_CTRLSTRATEGY_SYNC') CREATE INDEX IDX_T_CTSY_CTRLSTRATEGY_SYNC ON T_CTSY_CTRLSTRATEGY_SYNC ( FUID );


EXEC P_ALTERPK 'PK_T_CTSY_CTRL_SYNC_DATA', 'T_CTSY_CTRL_SYNC_DATA', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTSY_CTRL_SYNC_DATA') CREATE INDEX IDX_CTSY_CTRL_SYNC_DATA ON T_CTSY_CTRL_SYNC_DATA ( FID ,FDATAID );


EXEC P_ALTERPK 'PK_T_CTSY_CTRL_SYNC_ORG', 'T_CTSY_CTRL_SYNC_ORG', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CTSY_CTRL_SYNC_ORG') CREATE INDEX IDX_CTSY_CTRL_SYNC_ORG ON T_CTSY_CTRL_SYNC_ORG ( FID ,FORGID );

 