USE bi_dm
GO
/* Add missing include columns */
-- NCIX_DM_Sale_Sale_pharmacy_SAL_doc_number
--IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Sale'), 'NCIX_DM_Sale_Sale_pharmacy_SAL_doc_number' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.DM_Sale.NCIX_DM_Sale_Sale_pharmacy_SAL_doc_number;
--END;
-- GO
-- IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Sale'), 'NCIX_DM_Sale_Sale_pharmacy_SAL_doc_number' , 'IndexID' ) IS NULL BEGIN;
    -- CREATE INDEX NCIX_DM_Sale_Sale_pharmacy_SAL_doc_number ON dbo.DM_Sale(Sale_pharmacy, SAL_doc_number) 
    -- INCLUDE(
        -- Sale_ID, SAL_value_date, SAL_pharmacode, SAL_quantity, SAL_amount_VAT, SAL_discount, SAL_prescription, 
        -- SAL_prescription_number, SAL_original_prescription_number, SAL_prescriber_CAMS_code, SAL_insurance, 
        -- SAL_posology, SAL_turnover_type, SAL_correction_ID, 
        -- [SAL_text], [SAL_linked_sale_id], [SAL_original_date], [SAL_prescription_pharmacy]
    -- );
-- END;
-- GO


/* create missing index */
-- NCIX_DM_Prescriber_CAMS_code
--IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Prescriber'), 'NCIX_DM_Prescriber_CAMS_code' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.DM_Prescriber.NCIX_DM_Prescriber_CAMS_code;
--END;
--GO
--IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Prescriber'), 'NCIX_DM_Prescriber_CAMS_code' , 'IndexID' ) IS NULL BEGIN;
--    CREATE INDEX NCIX_DM_Prescriber_CAMS_code ON dbo.DM_Prescriber(PRESC_CAMS_code)
--    INCLUDE(PRESC_name);
--END;
--GO

/* Create missing index */
-- -- NCIX_DM_Sale_COL_Sale_pharmacy_Sale_id
-- IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Sale'), 'NCIX_DM_Sale_COL_Sale_pharmacy_Sale_id' , 'IndexID' ) IS NOT NULL BEGIN;
    -- DROP INDEX dbo.DM_Sale.NCIX_DM_Sale_COL_Sale_pharmacy_Sale_id;
-- END;
-- GO
-- IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Sale'), 'NCIX_DM_Sale_COL_Sale_pharmacy_Sale_id' , 'IndexID' ) IS NULL BEGIN;
    -- CREATE INDEX NCIX_DM_Sale_COL_Sale_pharmacy_Sale_id ON dbo.DM_Sale(Sale_pharmacy, Sale_ID) INCLUDE(SAL_operation_code,SAL_correction_id);
-- END;
-- GO


/* Create missing index */
-- NCIX_DM_item_Phcode_tarif_type
--IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Item'), 'NCIX_DM_item_Phcode_tarif_type' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.DM_Item.NCIX_DM_item_Phcode_tarif_type;
--END;
--GO
--IF INDEXPROPERTY(OBJECT_ID('dbo.DM_Item'), 'NCIX_DM_item_Phcode_tarif_type' , 'IndexID' ) IS NULL BEGIN;
--    CREATE INDEX NCIX_DM_item_Phcode_tarif_type ON dbo.DM_Item(Item_pharmacode, IT_PH_tarif_type);
--END;
--GO


USE [BI_BAS]
GO
/* Create missing index */
---- IDX_BAS_T1_ORGANIZATIONAL_UNIT_ORGANIZATIONAL_id_sub_code
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_ORGANIZATIONAL_UNIT'), 'IDX_BAS_T1_ORGANIZATIONAL_UNIT_ORGANIZATIONAL_id_sub_code' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.BAS_T1_ORGANIZATIONAL_UNIT.IDX_BAS_T1_ORGANIZATIONAL_UNIT_ORGANIZATIONAL_id_sub_code;
--END;
--GO
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_ORGANIZATIONAL_UNIT'), 'IDX_BAS_T1_ORGANIZATIONAL_UNIT_ORGANIZATIONAL_id_sub_code' , 'IndexID' ) IS NULL BEGIN;
--    CREATE INDEX IDX_BAS_T1_ORGANIZATIONAL_UNIT_ORGANIZATIONAL_id_sub_code ON dbo.BAS_T1_ORGANIZATIONAL_UNIT(ORGANIZATIONAL_UNIT_SYSTEMINSTANCE_ID, OU_SUBSIDIARY) INCLUDE(OU_CODE);
--END;
--GO

---- IDX_BAS_T1_DOCUMENT_TYPE_DTY_TYPE
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_DOCUMENT_TYPE'), 'IDX_BAS_T1_DOCUMENT_TYPE_covering' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.BAS_T1_DOCUMENT_TYPE.IDX_BAS_T1_DOCUMENT_TYPE_covering;
--END;
--GO
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_DOCUMENT_TYPE'), 'IDX_BAS_T1_DOCUMENT_TYPE_covering' , 'IndexID' ) IS NULL BEGIN;
--    CREATE INDEX IDX_BAS_T1_DOCUMENT_TYPE_covering ON dbo.BAS_T1_DOCUMENT_TYPE(DTY_TYPE, [DOCUMENT_TYPE_ID], [DOCUMENT_TYPE_SYSTEMINSTANCE_ID])
--    INCLUDE([DTY_DEBIT_CREDIT_CODE]);
--END;
--GO

---- IDX_BAS_T1_PREDEFINED_ENTRY_PD_DOCUMENT_TYPE
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_PREDEFINED_ENTRY'), 'IDX_BAS_T1_PREDEFINED_ENTRY_PD_DOCUMENT_TYPE' , 'IndexID' ) IS NOT NULL BEGIN;
--    DROP INDEX dbo.BAS_T1_PREDEFINED_ENTRY.IDX_BAS_T1_PREDEFINED_ENTRY_PD_DOCUMENT_TYPE;
--END;
--GO
--IF INDEXPROPERTY(OBJECT_ID('dbo.BAS_T1_PREDEFINED_ENTRY'), 'IDX_BAS_T1_PREDEFINED_ENTRY_PD_DOCUMENT_TYPE' , 'IndexID' ) IS NULL BEGIN;
--    CREATE INDEX IDX_BAS_T1_PREDEFINED_ENTRY_PD_DOCUMENT_TYPE ON dbo.BAS_T1_PREDEFINED_ENTRY(PD_DOCUMENT_TYPE, [PREDEFINED_ENTRY_SYSTEMINSTANCE_ID])
--    INCLUDE([PD_CODE]);
--END;
--GO




