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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_SYNCUSERBYORG')
 CREATE TABLE T_ER_SYNCUSERBYORG (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL,
FLASTSYNCSTAMP DATETIME
);



 EXEC P_ALTERPK 'PK_T_ER_SYNCUSERBYORG', 'T_ER_SYNCUSERBYORG', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_SUBO_FID') CREATE INDEX IDX_ER_SUBO_FID ON T_ER_SYNCUSERBYORG ( FID ,FSEQ );

update T_ER_BIZ_INFO set FSYNCUSERTYPE = '1' where FSYNCUSERTYPE = ' ';