/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2021/11/25 10:12:32                          */
/*==============================================================*/

/*==============================================================*/
/* Table: T_EB_DECOMPOSE_SCHEME                                 */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DECOMPOSE_SCHEME')
CREATE TABLE T_EB_DECOMPOSE_SCHEME (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FMODEL               BIGINT               NOT NULL DEFAULT 0,
   FBIZMODELID          BIGINT               NOT NULL DEFAULT 0,
   FNUMBER              VARCHAR(50)          NOT NULL DEFAULT ' ',
   FNAME                VARCHAR(80)          NOT NULL DEFAULT ' ',
   FVERSION             BIGINT               NOT NULL DEFAULT 0,
   FDATATYPE            BIGINT               NOT NULL DEFAULT 0,
   FSTATUS              VARCHAR(2)           NOT NULL DEFAULT '0',
   FMODIFYOPERATOR      BIGINT               NOT NULL DEFAULT 0,
   FCREATEOPERATOR      BIGINT               NOT NULL DEFAULT 0,
   FCREATETIME          DATETIME             NOT NULL,
   FMODIFYTIME          DATETIME             NOT NULL,
   FAUDITTRAIL          BIGINT               NOT NULL DEFAULT 0,
   FTYPE                VARCHAR(2)           NOT NULL DEFAULT '0',
   FCURRENCY            BIGINT               NOT NULL DEFAULT 0,
   FTARGETRECORD        BIGINT               NOT NULL DEFAULT 0,
   FBUDGETPERIOD        VARCHAR(2000)        NOT NULL DEFAULT ' '
);
EXEC P_ALTERPK 'PK_EB_DECOMPOSE_SCHEME', 'T_EB_DECOMPOSE_SCHEME', 'FID', '1';

/*==============================================================*/
/* Index: INDEX_MODEL_SO_ON                                     */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSE_SCHEME_P1')
 CREATE INDEX IDX_EB_DECOMPOSE_SCHEME_P1 ON T_EB_DECOMPOSE_SCHEME ( FMODEL,FVERSION,FDATATYPE,FCURRENCY,FAUDITTRAIL );


/*==============================================================*/
/* Index: INDEX_MODEL_NUMBER                                    */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSE_SCHEME_P2')
 CREATE INDEX IDX_EB_DECOMPOSE_SCHEME_P2 ON T_EB_DECOMPOSE_SCHEME ( FMODEL,FNUMBER);


/*==============================================================*/
/* Table: T_EB_DECOMPOSEADJUST                                  */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DECOMPOSEADJUST')
CREATE TABLE T_EB_DECOMPOSEADJUST (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FMODEL               BIGINT               NOT NULL DEFAULT 0,
   FBIZMODEL            BIGINT               NOT NULL DEFAULT 0,
   FDATASET             BIGINT               NOT NULL DEFAULT 0,
   FENTITY              BIGINT               NOT NULL DEFAULT 0,
   FACCOUNT             BIGINT               NOT NULL DEFAULT 0,
   FBUDGETPERIOD        BIGINT               NOT NULL DEFAULT 0,
   FAUDITTRAIL          BIGINT               NOT NULL DEFAULT 0,
   FVERSION             BIGINT               NOT NULL DEFAULT 0,
   FDATATYPE            BIGINT               NOT NULL DEFAULT 0,
   FCURRENCY            BIGINT               NOT NULL DEFAULT 0,
   FHASHCODE            BIGINT               NOT NULL DEFAULT 0,
   FDIMENSIONJSON       NCLOB       NOT NULL DEFAULT ' ',
   FSTATE               INT             NOT NULL DEFAULT 0
);
EXEC P_ALTERPK 'PK_EB_DECOMPOSEADJUST', 'T_EB_DECOMPOSEADJUST', 'FID', '1';

/*==============================================================*/
/* Index: MULTI_FIELD_KEY                                       */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_P1')
 CREATE INDEX IDX_EB_DECOMPOSEADJUST_P1 ON T_EB_DECOMPOSEADJUST ( FMODEL,FHASHCODE);

/*==============================================================*/
/* Table: T_EB_DECOMPOSEADJUSTSUB                               */
/*==============================================================*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DECOMPOSEADJUSTSUB')
CREATE TABLE T_EB_DECOMPOSEADJUSTSUB (
   FENTRYID             BIGINT               NOT NULL DEFAULT 0,
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FSEQ                 INT                  NOT NULL DEFAULT 0,
   FTYPE                INT                  NOT NULL DEFAULT 1,
   FPENDINGTRIAL        DECIMAL(23,10)       NOT NULL DEFAULT 0,
   FFIXTRIAL            DECIMAL(23,10)       NOT NULL DEFAULT 0,
   FADJUSTTRIAL         DECIMAL(23,10)       NOT NULL DEFAULT 0,
   FADJUSTEXPLAIN       VARCHAR(255)         NOT NULL DEFAULT '',
   FMODIFYOPERATOR      BIGINT               NOT NULL DEFAULT 0,
   FMODIFYTIME          DATETIME             NOT NULL,
   FSTATUS              INT                  NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_EB_DECOMPOSEADJUSTSUB', 'T_EB_DECOMPOSEADJUSTSUB', 'FENTRYID', '1';

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