-- 修改轻分析数据源表增加期间字段类型字段 默认值为1
/**BEGIN  **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_QINGANALYSISDS' AND KSQL_COL_NAME IN ('FBPFIELDTYPE'))
ALTER TABLE T_EB_QINGANALYSISDS ADD (FBPFIELDTYPE VARCHAR(50) DEFAULT '2');

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_QINGDS_MVAR')
CREATE TABLE T_EB_QINGDS_MVAR
(
    FID            BIGINT DEFAULT 0 NOT NULL,
    FMODELID       BIGINT DEFAULT 0 NOT NULL,
    FDIMENSIONID   BIGINT DEFAULT 0 NOT NULL,
    FVARIABLEID    BIGINT DEFAULT 0 NOT NULL,
    FVARNUMBER     NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FUSECOUNT      BIGINT DEFAULT 0 NOT NULL,
    FVARIABLEJSON  NVARCHAR(100) DEFAULT ' ' NOT NULL
);
-- 主键
EXEC P_ALTERPK 'PK_EB_QINGDS_MVAR', 'T_EB_QINGDS_MVAR', 'FID', '1';
-- 索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_QINGDS_M')
CREATE INDEX IDX_EB_QINGDS_M ON T_EB_QINGDS_MVAR ( FMODELID );
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_QINGDS_V')
CREATE INDEX IDX_EB_QINGDS_V ON T_EB_QINGDS_MVAR ( FVARIABLEID );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_QINGDS_VAR')
CREATE TABLE T_EB_QINGDS_VAR
(
    FID            BIGINT DEFAULT 0 NOT NULL,
    FQINGDSID      BIGINT DEFAULT 0 NOT NULL,
    FDIMENSIONID   BIGINT DEFAULT 0 NOT NULL,
    FVARIABLEID    BIGINT DEFAULT 0 NOT NULL,
    FVARNUMBER     NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FVARIABLEJSON  NVARCHAR(100) DEFAULT ' ' NOT NULL
);
-- 主键
EXEC P_ALTERPK 'PK_EB_QINGDS_VAR', 'T_EB_QINGDS_VAR', 'FID', '1';
-- 索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_QINGDS_ID')
CREATE INDEX IDX_EB_QINGDS_ID ON T_EB_QINGDS_VAR ( FQINGDSID );

/**END **/
