IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_LICSYNCDETAILLOG') 
 CREATE TABLE T_LIC_LICSYNCDETAILLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FTASKID BIGINT DEFAULT 0 NOT NULL,
FISSUCCESS CHAR(1) DEFAULT '0' NOT NULL,
FREASON NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPERATION NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOGTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FPHONE VARCHAR(36) DEFAULT ' ' NOT NULL,
FEMAIL VARCHAR(100) DEFAULT ' ' NOT NULL,
FUSERNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_LICENSESYNCLOGCLEAN') 
 CREATE TABLE T_LIC_LICENSESYNCLOGCLEAN (
FID BIGINT DEFAULT 0 NOT NULL,
FDAY INT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_LICSYNCLOG') 
 CREATE TABLE T_LIC_LICSYNCLOG (
FID BIGINT DEFAULT 0 NOT NULL,
FOPNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOPDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOPTIME DATETIME,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FCOMPARE VARCHAR(30) DEFAULT ' ' NOT NULL,
FISSUCCESS CHAR(1) DEFAULT '0'
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_LIC_USERLICENSEGROUP' AND KSQL_COL_NAME ='FMAINORGNAME') 
 ALTER TABLE T_LIC_USERLICENSEGROUP ADD (FMAINORGNAME NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_LIC_USERLICENSEGROUP' AND KSQL_COL_NAME ='FMAINORGFULLNAME') 
 ALTER TABLE T_LIC_USERLICENSEGROUP ADD (FMAINORGFULLNAME NVARCHAR(255) DEFAULT ' ' NOT NULL );
 
EXEC P_ALTERPK 'PK_T_LIC_LICSYNCDETAILLOG', 'T_LIC_LICSYNCDETAILLOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_LICSYNCDETAILLOG_TASK') CREATE INDEX IX_LICSYNCDETAILLOG_TASK ON T_LIC_LICSYNCDETAILLOG ( FTASKID );


EXEC P_ALTERPK 'PK_T_LIC_LICENSESYNCLOGCLEAN', 'T_LIC_LICENSESYNCLOGCLEAN', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LICENSESYNCLOGCLEAN_DAY') CREATE INDEX IDX_LICENSESYNCLOGCLEAN_DAY ON T_LIC_LICENSESYNCLOGCLEAN ( FDAY );


EXEC P_ALTERPK 'PK_T_LIC_LICSYNCLOG', 'T_LIC_LICSYNCLOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_LIC_LICSYNCLOG_USERID') CREATE INDEX IX_LIC_LICSYNCLOG_USERID ON T_LIC_LICSYNCLOG ( FUSERID );
