IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_DATALINE') 
 CREATE TABLE T_MSPLAN_DATALINE (
	FID                BIGINT             DEFAULT 0      NOT NULL,
	FENTRYID           BIGINT             DEFAULT 0      NOT NULL,
	FSEQ               INT                DEFAULT 0      NOT NULL,
	FDATALINETYPE      NVARCHAR(5)        DEFAULT ' '    NOT NULL,
	FLINESHAPE         NVARCHAR(5)        DEFAULT ' '    NOT NULL,
	FLINECOLORVALUE    NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FLINECOLOR         NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FISSHOW            CHAR(1)            DEFAULT '0'    NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_HOLIDAY') 
 CREATE TABLE T_MSPLAN_HOLIDAY (
	FID                BIGINT             DEFAULT 0      NOT NULL,
	FENTRYID           BIGINT             DEFAULT 0      NOT NULL,
	FSEQ               INT                DEFAULT 0      NOT NULL,
	FFESTIVALNAME      NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FSTARTDATERANGE    DATETIME,
	FENDDATERANGE      DATETIME,
	FFCOLORVALUE       NVARCHAR(50)       DEFAULT ' '    NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_PERSON_COLOR') 
 CREATE TABLE T_MSPLAN_PERSON_COLOR (
	FID                   BIGINT             DEFAULT 0      NOT NULL,
	FENTRYID              BIGINT             DEFAULT 0      NOT NULL,
	FSEQ                  INT                DEFAULT 0      NOT NULL,
	FCOLORVALUE           NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FCOLORCONDITON        NVARCHAR(1000)     DEFAULT ' '    NOT NULL,
	FCOLORCONDFILTER      NVARCHAR(255)      DEFAULT ' '    NOT NULL,
	FCOLORCONDFILTER_TAG  NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_QUICK_DFILED') 
 CREATE TABLE T_MSPLAN_QUICK_DFILED (
	FID                   BIGINT             DEFAULT 0      NOT NULL,
	FENTRYID              BIGINT             DEFAULT 0      NOT NULL,
	FSEQ                  INT                DEFAULT 0      NOT NULL,
	FFIELDNAME            NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FHIDECOL              CHAR(1)            DEFAULT '0'    NOT NULL,
	FREQUIREDITEM         CHAR(1)            DEFAULT '0'    NOT NULL,
	FFIELDFLAG            NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FFILEDID              NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FREFBASEFIELDID       NVARCHAR(50)       DEFAULT ' '    NOT NULL,
	FTYPE                 NVARCHAR(50)       DEFAULT ' '    NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_FENTRYETY_L') 
CREATE TABLE T_MSPLAN_FENTRYETY_L
(
    FPKID                 NVARCHAR(255)      DEFAULT ' '    NOT NULL,        
    FENTRYID              BIGINT             DEFAULT 0      NOT NULL,         
    FLOCALEID             NVARCHAR(255)      DEFAULT ' '    NOT NULL,          
    FENTRYFIELDALIGN      NVARCHAR(50)       DEFAULT ' '    NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_ENTITY_CONDITION') 
CREATE TABLE T_MSPLAN_ENTITY_CONDITION
(
    FENTRYID              BIGINT             DEFAULT 0      NOT NULL,          
    FDETAILID             BIGINT             DEFAULT 0      NOT NULL,   
    FSEQ                  INT                DEFAULT 0      NOT NULL,            
    FCENTITYID            NVARCHAR(255)      DEFAULT ' '    NOT NULL, 	
    FCFILTERTEXT          NVARCHAR(1000)     DEFAULT ' '    NOT NULL, 	
    FCFILTER              NVARCHAR(255)      DEFAULT ' '    NOT NULL, 
    FCFILTER_TAG          NCLOB, 	
    FFIELDSORT            NVARCHAR(50)       DEFAULT ' '    NOT NULL, 	
    FFIELDSORTFLAG        NVARCHAR(50)       DEFAULT ' '    NOT NULL
);




IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_GTTSOURCE' AND KSQL_COL_NAME ='FENTITYLAYOUTID') 
 ALTER TABLE T_MSPLAN_GTTSOURCE ADD (FENTITYLAYOUTID NVARCHAR(255) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_GTTSOURCE' AND KSQL_COL_NAME ='FHIGHLIGHTGROUP') 
 ALTER TABLE T_MSPLAN_GTTSOURCE ADD (FHIGHLIGHTGROUP NVARCHAR(50) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_GTTSOURCE' AND KSQL_COL_NAME ='FHIGHLIGHTGROUPFLAG') 
 ALTER TABLE T_MSPLAN_GTTSOURCE ADD (FHIGHLIGHTGROUPFLAG NVARCHAR(50) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FPLANAREA') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FPLANAREA CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FTODOAREA') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FTODOAREA CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FSUMMARYAREA') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FSUMMARYAREA CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FMONDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FMONDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FTUESDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FTUESDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FWEDNESDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FWEDNESDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FTHURSDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FTHURSDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FFRIDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FFRIDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FSATURDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FSATURDAY CHAR(1) DEFAULT '0' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_VWSCHEME' AND KSQL_COL_NAME ='FSUNDAY') 
 ALTER TABLE T_MSPLAN_VWSCHEME ADD (FSUNDAY CHAR(1) DEFAULT '0' NOT NULL );
