/**BEGIN E:\NEXTERP_PDM\PDM_UPGRADE\PDMS\BRANCH_LASTEST\PDM\EB_TABLE.SQL **/

-- 主键索引
EXEC P_ALTERPK 'PK_T_EB_MEMBERQUOTE', 'T_EB_MEMBERQUOTE', 'FID', '1';
EXEC P_ALTERPK 'PK_T_EB_MEMBERQUOTEENTRY', 'T_EB_MEMBERQUOTEENTRY', 'FID', '1';

-- 唯一索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'UX_EB_MEMBERQUOTE')
CREATE UNIQUE INDEX UX_EB_MEMBERQUOTE ON T_EB_MEMBERQUOTE ( FMODELID, FDIMENSIONID, FMEMBERID, FTYPE );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_MEMBERQUOTEENTRY')
CREATE INDEX IX_EB_MEMBERQUOTEENTRY ON T_EB_MEMBERQUOTEENTRY ( FQUOTEID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_MEMBERQUOTEENTRY_RES')
CREATE INDEX IX_EB_MEMBERQUOTEENTRY_RES ON T_EB_MEMBERQUOTEENTRY ( FSOURCEID, FSOURCETYPE );




-- 任务分配组织索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_TASKSAVE_ORG')
CREATE INDEX IDX_EB_TASKSAVE_ORG ON T_EB_TASKSAVE ( FORGID );


-- 币别折算方案
-- 原币索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CURRENCYCONVERT_RAW')
CREATE INDEX IDX_EB_CURRENCYCONVERT_RAW ON T_EB_CURRENCYCONVERTSCHEM ( FCURRENCYRAW );

-- 折算币索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CURRENCYCONVERT_RATE')
CREATE INDEX IDX_EB_CURRENCYCONVERT_RATE ON T_EB_CURRENCYCONVERTSCHEM ( FCURRENCYRATE );


-- 滚动预算的数据结构调整
EXEC P_ALTERCOLUMN 'T_EB_ROLLCONFIG', 'FSTARTDATE', 'BIGINT', 'NOT NULL', '1001', '0';
EXEC P_ALTERCOLUMN 'T_EB_ROLLCONFIG', 'FACTVERSION', 'BIGINT', 'NOT NULL', '1001', '0';
EXEC P_ALTERCOLUMN 'T_EB_ROLLCONFIG', 'FDATATYPE', 'BIGINT', 'NOT NULL', '1001', '0';
EXEC P_ALTERCOLUMN 'T_EB_ROLLCONFIG', 'FVERSION', 'BIGINT', 'NOT NULL', '1001', '0';


--滚动预算索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ROLLCONFIG_SD')
CREATE INDEX IDX_EB_ROLLCONFIG_SD ON T_EB_ROLLCONFIG ( FSTARTDATE );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ROLLCONFIG_AV')
CREATE INDEX IDX_EB_ROLLCONFIG_AV ON T_EB_ROLLCONFIG ( FACTVERSION );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ROLLCONFIG_DT')
CREATE INDEX IDX_EB_ROLLCONFIG_DT ON T_EB_ROLLCONFIG ( FDATATYPE );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ROLLCONFIG_VER')
CREATE INDEX IDX_EB_ROLLCONFIG_VER ON T_EB_ROLLCONFIG ( FVERSION );


-- 报表实例
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_REPORTPROCESS_ENT')
CREATE INDEX IDX_EB_REPORTPROCESS_ENT ON T_EB_REPORTPROCESS ( FENTITY );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_REPORTPROCESS_VER')
CREATE INDEX IDX_EB_REPORTPROCESS_VER ON T_EB_REPORTPROCESS ( FVERSION );


-- 业务管控范围
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VIEWENTRY_DIM')
CREATE INDEX IDX_EB_VIEWENTRY_DIM ON T_EB_VIEWENTRY ( FDIMENSIONID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VIEWENTRY_VIEW')
CREATE INDEX IDX_EB_VIEWENTRY_VIEW ON T_EB_VIEWENTRY ( FVIEWID );


-- 视图引用维度
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DIMENSIONVIEW_DIM')
CREATE INDEX IDX_EB_DIMENSIONVIEW_DIM ON T_EB_DIMENSIONVIEW ( FDIMENSIONID );


-- 视图引用成员
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VIEWMEMBER_MEM')
CREATE INDEX IDX_EB_VIEWMEMBER_MEM ON T_EB_VIEWMEMBER ( FMEMBERID );


-- 调整分解索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_ENT')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_ENT ON T_EB_DECOMPOSEADJUST ( FENTITY );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_ACC')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_ACC ON T_EB_DECOMPOSEADJUST ( FACCOUNT );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_BP')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_BP ON T_EB_DECOMPOSEADJUST ( FBUDGETPERIOD );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_AT')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_AT ON T_EB_DECOMPOSEADJUST ( FAUDITTRAIL );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_VER')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_VER ON T_EB_DECOMPOSEADJUST ( FVERSION );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_DT')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_DT ON T_EB_DECOMPOSEADJUST ( FDATATYPE );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DECOMPOSEADJUST_CUEE')
CREATE INDEX IDX_EB_DECOMPOSEADJUST_CUEE ON T_EB_DECOMPOSEADJUST ( FCURRENCY );


-- 数据集引用维度
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DATASETDIM_DIM')
CREATE INDEX IDX_EB_DATASETDIM_DIM ON T_EB_DATASETDIM ( FDATASETDIM );



/**END E:\NEXTERP_PDM\PDM_UPGRADE\PDMS\BRANCH_LASTEST\PDM\EB_TABLE.SQL **/