IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_USERBITMAPINDEX')
 CREATE TABLE T_LIC_USERBITMAPINDEX (
FID BIGINT DEFAULT 0 NOT NULL,
FPHONE VARCHAR(36) DEFAULT ' ' NOT NULL,
FEMAIL VARCHAR(100) DEFAULT ' ' NOT NULL,
FUSERNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FBITMAPINDEX BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_LICDETAIL_TRIAL')
 CREATE TABLE T_LIC_LICDETAIL_TRIAL (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FTOTALCOUNT INT DEFAULT 0 NOT NULL,
FASSIGNEDCOUNT INT DEFAULT 0 NOT NULL,
FREMAINCOUNT INT DEFAULT 0 NOT NULL,
FBEGINDATE DATETIME,
FENDDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_USERLICGROUP_TRIAL')
 CREATE TABLE T_LIC_USERLICGROUP_TRIAL (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FSYNCSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FMAINORGNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMAINORGFULLNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FASSIGNTIME DATETIME,
FLICENSESOURCE VARCHAR(10) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_LICGROUPAPPS_TRIAL')
 CREATE TABLE T_LIC_LICGROUPAPPS_TRIAL (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FBIZAPPID VARCHAR(36) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_LIC_USERLICENSEGROUP' AND KSQL_COL_NAME ='FLICENSESOURCE')
 ALTER TABLE T_LIC_USERLICENSEGROUP ADD (FLICENSESOURCE VARCHAR(10) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_SNAPSHOT')
 CREATE TABLE T_LIC_SNAPSHOT (
FID BIGINT DEFAULT 0 NOT NULL,
FDATA NCLOB,
FCREATETIME DATETIME
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_LIC_GROUPBITMAP')
 CREATE TABLE T_LIC_GROUPBITMAP (
FID BIGINT DEFAULT 0 NOT NULL,
FGROUPID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FBITMAP NCLOB,
FSIGN VARCHAR(256) DEFAULT ' ' NOT NULL
);
 EXEC p_AlterColumn 'T_LIC_GROUPBITMAP', 'FBITMAP', 'BLOB', 'NULL', '1111', 'NULL';

 EXEC P_ALTERPK 'PK_T_LIC_LICENSE_TRIAL', 'T_LIC_LICENSE_TRIAL', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LIC_LICENSE_TRIAL_PIC') CREATE INDEX IDX_LIC_LICENSE_TRIAL_PIC ON T_LIC_LICENSE_TRIAL ( FPRODINSTCODE );


EXEC P_ALTERPK 'PK_T_LIC_LICDETAIL_TRIAL', 'T_LIC_LICDETAIL_TRIAL', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LIC_LICDETAIL_TRIAL_LIC') CREATE INDEX IDX_LIC_LICDETAIL_TRIAL_LIC ON T_LIC_LICDETAIL_TRIAL ( FID );


EXEC P_ALTERPK 'PK_T_LIC_LICGROUPAPPS_TRIAL', 'T_LIC_LICGROUPAPPS_TRIAL', 'FDETAILID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LIC_LICGROUPAPP_TRIAL_UG') CREATE INDEX IDX_LIC_LICGROUPAPP_TRIAL_UG ON T_LIC_LICGROUPAPPS_TRIAL ( FENTRYID );


EXEC P_ALTERPK 'PK_T_LIC_USERLICGROUP_TRIAL', 'T_LIC_USERLICGROUP_TRIAL', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LIC_USERLICGROUP_TRIAL_UG') CREATE INDEX IDX_LIC_USERLICGROUP_TRIAL_UG ON T_LIC_USERLICGROUP_TRIAL ( FUSERID ,FGROUPID );


EXEC P_ALTERPK 'PK_T_LIC_SNAPSHOT', 'T_LIC_SNAPSHOT', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_LIC_SNAPSHOT_CREATETIME') CREATE INDEX IDX_T_LIC_SNAPSHOT_CREATETIME ON T_LIC_SNAPSHOT ( FCREATETIME );


EXEC P_ALTERPK 'PK_T_LIC_USERBITMAPINDEX', 'T_LIC_USERBITMAPINDEX', 'FID,FPHONE,FEMAIL,FUSERNAME,FBITMAPINDEX', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_LIC_USERBITMAPINDEX_BITMAP') CREATE INDEX IDX_LIC_USERBITMAPINDEX_BITMAP ON T_LIC_USERBITMAPINDEX ( FBITMAPINDEX );


EXEC P_ALTERPK 'PK_T_LIC_GROUPBITMAP', 'T_LIC_GROUPBITMAP', 'FID,FGROUPID,FSIGN', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'UX_T_LIC_GROUPBITMAP_GROUP') CREATE UNIQUE INDEX UX_T_LIC_GROUPBITMAP_GROUP ON T_LIC_GROUPBITMAP ( FGROUPID );

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