Scripts for SCPL1

Embed Size (px)

Citation preview

  • 8/6/2019 Scripts for SCPL1

    1/22

    ----------------------MainDb

    create Nonclustered Index NCI_AccessLevel_1 on AccessLevel(LoginID)Gocreate Nonclustered Index NCI_Customer_1 on Customer(CustActive) include (custcode,custname)Gocreate Nonclustered Index NCI_Customer_2 on Customer(AccId)Gocreate Nonclustered Index NCI_despatch_1 on despatch(Prodid,gradeid)Gocreate Nonclustered Index NCI_despatch_2 on despatch(PoProductId)Gocreate Nonclustered Index NCI_despatch_5 on despatch(InvoiceNo)Gocreate Nonclustered Index NCI_Employee_1 on Employee(DeptId)Gocreate Nonclustered Index NCI_Employee_2 on Employee(LocationId)Go

    create Nonclustered Index NCI_Invent_Grn_2 on Invent_Grn(TransportID)Gocreate Nonclustered Index NCI_Invent_Grn_3 on Invent_Grn(RebateClaimed)Gocreate Nonclustered Index NCI_Invent_Grn_4 on Invent_Grn(SupId) include(grndate,excinvoiceno)Gocreate Nonclustered Index NCI_Invent_Grn_5 on Invent_Grn(Grn_Ref_no)Gocreate Nonclustered Index NCI_Invent_Grn_6 on Invent_Grn(GrnNo)Gocreate Nonclustered Index NCI_Invent_Grn_7 on Invent_Grn(LocationID) include (supid)Gocreate Nonclustered Index NCI_Invent_Grn_9 on Invent_Grn(BillPassed) INCLUDE(Billable)Gocreate Nonclustered Index NCI_Invent_Grn_12 on Invent_Grn(GrnDate) include (Locationid,supid)Gocreate Nonclustered Index NCI_Invent_GrnDeliverySchedule_1 on Invent_GrnDeliverySchedule(DelSchID) include(Qty)Gocreate Nonclustered Index NCI_Invent_GrnDeliverySchedule_2 on Invent_GrnDeliverySchedule(GrnID)

    Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_1 on Invent_GrnMaterialdetail(GradeID)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_2 on Invent_GrnMaterialdetail(ProdnId,WhoAMI)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_4 on Invent_GrnMaterialdetail(POProductId)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_9 on Invent_GrnMaterialdetail(WinID)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_10 on Invent_GrnMaterialdetail(GRejDate)Go

  • 8/6/2019 Scripts for SCPL1

    2/22

    create Nonclustered Index NCI_Invent_GrnMaterialdetail_12 on Invent_GrnMaterialdetail(Inspected) include (QcReq)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_13 on Invent_GrnMaterialdetail(GrnNo)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_15 on Invent_GrnMaterialdetail(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnMaterialdetail_16 on Invent_GrnMaterialdetail(ReportNo)Gocreate Nonclustered Index NCI_Invent_GRNTax_2 on Invent_GRNTax(GrnID)Gocreate Nonclustered Index NCI_Invent_GRNTax_3 on Invent_GRNTax(TaxID)Gocreate Nonclustered Index NCI_Invent_Min_1 on Invent_Min(ReceiveId)Gocreate Nonclustered Index NCI_Invent_Min_2 on Invent_Min(VendorID)

    Gocreate Nonclustered Index NCI_Invent_Min_4 on Invent_Min(CSNo)Gocreate Nonclustered Index NCI_Invent_Min_5 on Invent_Min(DeptId)Gocreate Nonclustered Index NCI_Invent_Min_6 on Invent_Min(MinNo)Gocreate Nonclustered Index NCI_Invent_Min_7 on Invent_Min(LocationId)Gocreate Nonclustered Index NCI_Invent_Min_8 on Invent_Min(IssueId)Gocreate Nonclustered Index NCI_Invent_Min_10 on Invent_Min(MinDate)Gocreate Nonclustered Index NCI_Invent_Min_11 on Invent_Min(Min_Ref_No)Gocreate Nonclustered Index NCI_Invent_MinMaterial_1 on Invent_MinMaterial(Minno)Gocreate Nonclustered Index NCI_Invent_MinMaterial_2 on Invent_MinMaterial(MachineID)Gocreate Nonclustered Index NCI_Invent_MinMaterial_3 on Invent_MinMaterial(GRNID)Gocreate Nonclustered Index NCI_Invent_MinMaterial_4 on Invent_MinMaterial(GradeID)Gocreate Nonclustered Index NCI_Invent_MinMaterial_5 on Invent_MinMaterial(CSID)Gocreate Nonclustered Index NCI_Invent_MinMaterial_6 on Invent_MinMaterial(Rawmatid)Gocreate Nonclustered Index NCI_Invent_MinMaterial_7 on Invent_MinMaterial(srid)Gocreate Nonclustered Index NCI_Invent_POTax_1 on Invent_POTax(POID)Gocreate Nonclustered Index NCI_Invent_POTax_2 on Invent_POTax(TaxId)Gocreate Nonclustered Index NCI_Invent_Purchase_1 on Invent_Purchase(POID)Gocreate Nonclustered Index NCI_Invent_Purchase_2 on Invent_Purchase(SupID)Gocreate Nonclustered Index NCI_Invent_Purchase_3 on Invent_Purchase(LocationID)

  • 8/6/2019 Scripts for SCPL1

    3/22

    Gocreate Nonclustered Index NCI_Invent_Purchase_5 on Invent_Purchase(PODate)Gocreate Nonclustered Index NCI_Invent_Purchase_6 on Invent_Purchase(PONo)Gocreate Nonclustered Index NCI_Invent_PurchaseDelivery_1 on Invent_PurchaseDelivery(POProductID)Gocreate Nonclustered Index NCI_Invent_PurchaseDelivery_2 on Invent_PurchaseDelivery(DelSchedule)Gocreate Nonclustered Index NCI_Invent_Purchaseproduct_1 on Invent_Purchaseproduct(POID)Gocreate Nonclustered Index NCI_Invent_Purchaseproduct_3 on Invent_Purchaseproduct(RawmatId)Gocreate Nonclustered Index NCI_Invent_StorageLocationEntry_1 on Invent_StorageLocationEntry(Loc_Id)

    Gocreate Nonclustered Index NCI_Invent_StorageLocationEntry_2 on Invent_StorageLocationEntry(GRNID)GoCREATE NONCLUSTERED INDEX [NCI_Invent_StorageLocationEntry_3] ON [dbo].[Invent_ StorageLocationEntry] (Stock,GRNID) Include (loc_id,StockWt,StockVol) where (Stock> 0)Gocreate Nonclustered Index NCI_Invent_Supplier_2 on Invent_Supplier(CurrID)Gocreate Nonclustered Index NCI_Invent_Supplier_3 on Invent_Supplier(Acc_ID)Gocreate Nonclustered Index NCI_Invent_supplierprod_1 on Invent_supplierprod(SupId)Gocreate Nonclustered Index NCI_Invent_supplierprod_2 on Invent_supplierprod(RawMatId)Gocreate Nonclustered Index NCI_Invent_SupplierTax_1 on Invent_SupplierTax(SupId)Gocreate Nonclustered Index NCI_Invent_SupplierTax_2 on Invent_SupplierTax(RawmatId)Gocreate Nonclustered Index NCI_Invent_SupplierTax_3 on Invent_SupplierTax(LocationID)Gocreate Nonclustered Index NCI_Invent_SupplierTax_5 on Invent_SupplierTax(SupId,RawmatId,LocationID)Gocreate Nonclustered Index NCI_Invent_Transactions_1 on Invent_Transactions(StoreEntryID)Gocreate Nonclustered Index NCI_Invent_Transactions_2 on Invent_Transactions(RawmatID)Gocreate Nonclustered Index NCI_Invent_Transactions_3 on Invent_Transactions(LocationID)Gocreate Nonclustered Index NCI_Invent_Transactions_4 on Invent_Transactions(GrnID)Go

  • 8/6/2019 Scripts for SCPL1

    4/22

    create Nonclustered Index NCI_Invent_Transactions_5 on Invent_Transactions(TransnDate)Gocreate Nonclustered Index NCI_Invent_Transactions_6 on Invent_Transactions(DCID)

    where DCID>0Gocreate Nonclustered Index NCI_Invent_Transactions_7 on Invent_Transactions(TransferID) where TransferID>0Gocreate Nonclustered Index NCI_Invent_Transactions_8 on Invent_Transactions(SubconDetID) where SubconDetID>0Gocreate Nonclustered Index NCI_Invent_Transactions_10 on Invent_Transactions(RawmatId,TransnDate) INCLUDE ([StoreEntryID],[GrnID],[LocationQty],[MinQty],[MrnQty],[DCQty],[ScrapLocationQty],[SubconOutwardQty], [SubconInwardQty],[Description],[TransnType],[LocationID],[SAQty],[CharVals],[weight])Gocreate Nonclustered Index NCI_Invoice_1 on Invoice(InvID)Go

    create Nonclustered Index NCI_Invoice_2 on Invoice(LocationID)Gocreate Nonclustered Index NCI_Invoice_3 on Invoice(CustID)Gocreate Nonclustered Index NCI_Invoice_4 on Invoice(Billable,InvDone)Gocreate Nonclustered Index NCI_Invoice_5 on Invoice(InvDone)Gocreate Nonclustered Index NCI_Invoice_7 on Invoice(InvDate)Gocreate Nonclustered Index NCI_Invoice_8 on Invoice(InvDate1)Gocreate Nonclustered Index NCI_Invoice_9 on Invoice(InvoiceNo)Gocreate Nonclustered Index NCI_Invoice_10 on Invoice(InvoiceNo1)Gocreate Nonclustered Index NCI_PDForgingDetails_1 on PDForgingDetails(PDID,SlNo)Gocreate Nonclustered Index NCI_PDForgingDetails_2 on PDForgingDetails(ProcessID)Gocreate Nonclustered Index NCI_PDForgingDetails_3 on PDForgingDetails(PDID)Gocreate Nonclustered Index NCI_PDForgingDetails_4 on PDForgingDetails(SubCo)Gocreate Nonclustered Index NCI_PDForgingDetails_5 on PDForgingDetails(DeptId)Gocreate Nonclustered Index NCI_ProdnForgingStages_1 on ProdnForgingStages(Completed)Gocreate Nonclustered Index NCI_ProdnForgingStages_2 on ProdnForgingStages(DeptID)Gocreate Nonclustered Index NCI_ProdnForgingStages_3 on ProdnForgingStages(GradeID)Gocreate Nonclustered Index NCI_ProdnForgingStages_4 on ProdnForgingStages(ProdID)Gocreate Nonclustered Index NCI_ProdnForgingStages_5 on ProdnForgingStages(GroupBatchNo)Gocreate Nonclustered Index NCI_ProdnForgingStages_6 on ProdnForgingStages(GroupRefNo)

  • 8/6/2019 Scripts for SCPL1

    5/22

    Gocreate Nonclustered Index NCI_ProdnForgingStages_7 on ProdnForgingStages(LocationID)Gocreate Nonclustered Index NCI_ProdnForgingStages_9 on ProdnForgingStages(PDID)Gocreate Nonclustered Index NCI_ProdnForgingStages_10 on ProdnForgingStages(PostProcessID)Gocreate Nonclustered Index NCI_ProdnForgingStages_11 on ProdnForgingStages(PostSlNo)Gocreate Nonclustered Index NCI_ProdnForgingStages_12 on ProdnForgingStages(ProcessID)Gocreate Nonclustered Index NCI_ProdnForgingStages_13 on ProdnForgingStages(ShopTravelNo)Gocreate Nonclustered Index NCI_ProdnForgingStages_14 on ProdnForgingStages(StgDat

    e)Gocreate Nonclustered Index NCI_ProdnForgingStages_15 on ProdnForgingStages(WoNo)Gocreate Nonclustered Index NCI_ProdnMatDetails_1 on ProdnMatDetails(ProdnForgingStagesID)Gocreate Nonclustered Index NCI_ProdnMatDetails_2 on ProdnMatDetails(MinID)Gocreate Nonclustered Index NCI_ProdnPreId_1 on ProdnPreId(CurrId,CurrWhoAmI)Gocreate Nonclustered Index NCI_ProdnPreId_2 on ProdnPreId(PreId,PreWhoAmI)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_1 on ProdnSubContractorDetails(DCNo,SlNo)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_2 on ProdnSubContractorDetails(OutwardDate)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_3 on ProdnSubContractorDetails(InwardDate)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_4 on ProdnSubContractorDetails(ProcessSlNo)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_5 on ProdnSubContractorDetails(ProdID)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_6 on ProdnSubContractorDetails(PickForID)Gocreate Nonclustered Index NCI_ProdnSubContractorDetails_7 on ProdnSubContractorDetails(AutoRefNo)Gocreate Nonclustered Index NCI_Purchase_1 on Purchase(POID)Gocreate Nonclustered Index NCI_Purchase_2 on Purchase(PONo)Gocreate Nonclustered Index NCI_Purchase_3 on Purchase(PODate)Gocreate Nonclustered Index NCI_Purchase_4 on Purchase(LocationID)

  • 8/6/2019 Scripts for SCPL1

    6/22

    Gocreate Nonclustered Index NCI_Purchase_5 on Purchase(CustID)Gocreate Nonclustered Index NCI_Purchase_6 on Purchase(IntPONo)Gocreate Nonclustered Index NCI_PurchaseDelivery_1 on PurchaseDelivery(POProductID)Gocreate Nonclustered Index NCI_PurchaseDelivery_2 on PurchaseDelivery(DelSchedule)Gocreate Nonclustered Index NCI_purchaseproduct_1 on purchaseproduct(poid)Gocreate Nonclustered Index NCI_purchaseproduct_2 on purchaseproduct(ProdID)Gocreate Nonclustered Index NCI_RawMaterial_1 on RawMaterial(GrnTypeId)Gocreate Nonclustered Index NCI_Sales_CustSettingDetails_1 on Sales_CustSettingDetails(CustId,ProdId)

    Gocreate Nonclustered Index NCI_Sales_CustSettingDetails_2 on Sales_CustSettingDetails(CustId)Gocreate Nonclustered Index NCI_Sales_CustSettingDetails_3 on Sales_CustSettingDetails(ProdId)Gocreate Nonclustered Index NCI_Sales_CustTax_1 on Sales_CustTax(CustId,ProdID,LocationID)Gocreate Nonclustered Index NCI_Sales_CustTax_2 on Sales_CustTax(CustId)Gocreate Nonclustered Index NCI_Sales_CustTax_3 on Sales_CustTax(ProdID)Gocreate Nonclustered Index NCI_Sales_Despatch_Details_1 on Sales_Despatch_Details(DespatchID)Gocreate Nonclustered Index NCI_Sales_Despatch_Details_3 on Sales_Despatch_Details(SalesDespID)Gocreate Nonclustered Index NCI_Sales_InvoiceTaxDetails_1 on Sales_InvoiceTaxDetails(InvNo)Gocreate Nonclustered Index NCI_Sales_InvoiceTaxDetails_2 on Sales_InvoiceTaxDetails(TaxID)Gocreate Nonclustered Index NCI_WorkOrder_1 on WorkOrder(WoNo)Gocreate Nonclustered Index NCI_WorkOrder_2 on WorkOrder(Status) include (wono)Gocreate Nonclustered Index NCI_WorkOrder_3 on WorkOrder(WoDate)Gocreate Nonclustered Index NCI_WorkOrder_4 on WorkOrder(ProdID)Gocreate Nonclustered Index NCI_Invent_InspDimenDetails_1 on Invent_InspDimenDetails(GrnID) include(InspFrom)Gocreate Nonclustered Index NCI_messages_1 on messages(SourceMsgID)Gocreate Nonclustered Index NCI_messages_2 on messages(SenderID)Go

  • 8/6/2019 Scripts for SCPL1

    7/22

    create Nonclustered Index NCI_messages_3 on messages(RecipientID)Gocreate Nonclustered Index NCI_ProdnSubCoMatDetails_1 on ProdnSubCoMatDetails(SubConDetID)Gocreate Nonclustered Index NCI_ProdnSubCoMatDetails_2 on ProdnSubCoMatDetails(RawMatID)Gocreate Nonclustered Index NCI_ProdnSubCoMatDetails_3 on ProdnSubCoMatDetails(MinID)Gocreate Nonclustered Index NCI_ProdnSubCoMatDetails_4 on ProdnSubCoMatDetails(LostId)Gocreate Nonclustered Index NCI_invent_dimension_1 on invent_dimension(RawMatId)Gocreate Nonclustered Index NCI_invent_gateentrydetails_1 on invent_gateentrydetails(GateEntrydate)Go

    create Nonclustered Index NCI_invent_gateentrydetails_4 on invent_gateentrydetails(GateEntryNo)Gocreate Nonclustered Index NCI_invent_gateentrydetails_5 on invent_gateentrydetails(GateEntry_Ref_No)Gocreate Nonclustered Index NCI_invent_otherproperties_1 on invent_otherproperties(RawMatId)Gocreate Nonclustered Index NCI_machinecapacity_1 on machinecapacity(ForgeDetailID) include(DeptId,SubConId)Gocreate Nonclustered Index NCI_machinecapacity_2 on machinecapacity(PDID)Gocreate Nonclustered Index NCI_otherinspection_1 on otherinspection(InspectionID) Gocreate Nonclustered Index NCI_otherinspection_2 on otherinspection(QPID)Gocreate Nonclustered Index NCI_otherinspection_3 on otherinspection(InspStatus)Gocreate Nonclustered Index NCI_pdrmrequirement_1 on pdrmrequirement(PostForgingReqId)Gocreate Nonclustered Index NCI_pdrmrequirement_2 on pdrmrequirement(Pdid)Gocreate Nonclustered Index NCI_pdrmrequirement_3 on pdrmrequirement(RawMatId)Gocreate Nonclustered Index NCI_processdocument_1 on processdocument(ProdID,GradeID)Gocreate Nonclustered Index NCI_processdocument_2 on processdocument(PDStatus)Gocreate Nonclustered Index NCI_processdocument_3 on processdocument(Pdid) include(Route,IssueNo)Gocreate Nonclustered Index NCI_QualityPlan_1 on QualityPlan(ForgeDetailID)Gocreate Nonclustered Index NCI_QualityPlan_2 on QualityPlan(PDID)Gocreate Nonclustered Index NCI_Sales_ProductWiseInvoiceTaxDetails_1 on Sales_Prod

  • 8/6/2019 Scripts for SCPL1

    8/22

    uctWiseInvoiceTaxDetails(DespatchID)Gocreate Nonclustered Index NCI_WorkOrderPlan_1 on WorkOrderPlan(WoNo) include (shoptravelno)Gocreate Nonclustered Index NCI_CategoryAccess_1 on CategoryAccess(loginid) include (KeyName,Identification)Gocreate Nonclustered Index NCI_GRNAdditionalCost_1 on GRNAdditionalCost(GrnID)Gocreate Nonclustered Index NCI_Inv_CustomerReturnAddn_1 on Inv_CustomerReturnAddn(Af_Id)Gocreate Nonclustered Index NCI_Inv_GrnAddn_1 on Inv_GrnAddn(AF_ID)Gocreate Nonclustered Index NCI_Inv_GrnMatDetAddn_1 on Inv_GrnMatDetAddn(AF_ID)Gocreate Nonclustered Index NCI_Inv_RefiningInwardAddn_1 on Inv_RefiningInwardAddn(AF_ID)

    Gocreate Nonclustered Index NCI_Inv_RefiningOutwardAddn_1 on Inv_RefiningOutwardAddn(AF_ID)Gocreate Nonclustered Index NCI_Invent_AdditionalMatInfo_1 on Invent_AdditionalMatInfo(GrnId)Gocreate Nonclustered Index NCI_Invent_AdditionalMatInfo_2 on Invent_AdditionalMatInfo(RawmatId)Gocreate Nonclustered Index NCI_Invent_ChageSlipMatLocation_1 on Invent_ChageSlipMatLocation(CsId)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_1 on Invent_ChargeSlip(CSNo)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_2 on Invent_ChargeSlip(CS_Ref_No)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_3 on Invent_ChargeSlip(CSDate)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_4 on Invent_ChargeSlip(ProdId)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_5 on Invent_ChargeSlip(Status)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_6 on Invent_ChargeSlip(LinkedCSNo)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_8 on Invent_ChargeSlip(Type)Gocreate Nonclustered Index NCI_Invent_ChargeSlip_7 on Invent_ChargeSlip(LocationId)Gocreate Nonclustered Index NCI_Invent_ChargeSlipMaterial_1 on Invent_ChargeSlipMaterial(CSNo)Gocreate Nonclustered Index NCI_Invent_ChargeSlipMaterial_2 on Invent_ChargeSlipMaterial(RawmatId)Gocreate Nonclustered Index NCI_Invent_ChargeSlipMaterial_3 on Invent_ChargeSlipMaterial(grnid)Go

  • 8/6/2019 Scripts for SCPL1

    9/22

    create Nonclustered Index NCI_Invent_ChargeSlipMaterial_4 on Invent_ChargeSlipMaterial(ScrapId)Gocreate Nonclustered Index NCI_Invent_GateEntryAddn_1 on Invent_GateEntryAddn(Af_ Id)Gocreate Nonclustered Index NCI_Invent_GradeWeightedAverage_1 on Invent_GradeWeightedAverage(GradeId,AvgDate)Gocreate Nonclustered Index NCI_Invent_GrnCashIndent_1 on Invent_GrnCashIndent(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnCashIndent_2 on Invent_GrnCashIndent(PRId)Gocreate Nonclustered Index NCI_Invent_GrnComp_1 on Invent_GrnComp(GrnID)Gocreate Nonclustered Index NCI_Invent_GRNDeviation_1 on Invent_GRNDeviation(GrnId)

    Gocreate Nonclustered Index NCI_Invent_GrnDimen_1 on Invent_GrnDimen(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnMaterialCharacteristics_1 on Invent_GrnMaterialCharacteristics(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnMechanicalInspection_1 on Invent_GrnMechanicalInspection(GrnId)Gocreate Nonclustered Index NCI_Invent_GrnMix_1 on Invent_GrnMix(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnMix_2 on Invent_GrnMix(BaseGrnID)Gocreate Nonclustered Index NCI_Invent_GrnMix_3 on Invent_GrnMix(MixDate)Gocreate Nonclustered Index NCI_Invent_GrnMix_4 on Invent_GrnMix(MIxNo)Gocreate Nonclustered Index NCI_Invent_GrnOtherPropertyInspection_1 on Invent_GrnOtherPropertyInspection(GrnId)Gocreate Nonclustered Index NCI_Invent_GrnSort_1 on Invent_GrnSort(GrnID)Gocreate Nonclustered Index NCI_Invent_GrnSort_2 on Invent_GrnSort(BaseGrnID)Gocreate Nonclustered Index NCI_Invent_GrnWoNo_1 on Invent_GrnWoNo(GRNID)Gocreate Nonclustered Index NCI_Invent_MaterialAdditional_1 on Invent_MaterialAdditional(AF_ID)Gocreate Nonclustered Index NCI_Invent_MinQtyWithStorageLocation_1 on Invent_MinQtyWithStorageLocation(MinDetail_Id)Gocreate Nonclustered Index NCI_Invent_Mrn_1 on Invent_Mrn(Mrnno)Gocreate Nonclustered Index NCI_Invent_Mrn_2 on Invent_Mrn(DeptId)Gocreate Nonclustered Index NCI_Invent_Mrn_3 on Invent_Mrn(MrnDate) include (DeptId)Gocreate Nonclustered Index NCI_Invent_Mrn_4 on Invent_Mrn(Mrn_ref_no)Go

  • 8/6/2019 Scripts for SCPL1

    10/22

    create Nonclustered Index NCI_Invent_Mrn_5 on Invent_Mrn(CSNo)Gocreate Nonclustered Index NCI_Invent_Mrn_6 on Invent_Mrn(VendorID)Gocreate Nonclustered Index NCI_invent_mrnmaterial_1 on invent_mrnmaterial(Mrnno)Gocreate Nonclustered Index NCI_invent_mrnmaterial_2 on invent_mrnmaterial(Rawmatid)Gocreate Nonclustered Index NCI_invent_mrnmaterial_3 on invent_mrnmaterial(MIN_Id)Gocreate Nonclustered Index NCI_Invent_Returned_MRN_StoreDetail_1 on Invent_Returned_MRN_StoreDetail(MRN_Id)Gocreate Nonclustered Index NCI_Invent_StockTransfers_1 on Invent_StockTransfers(GrnID)Gocreate Nonclustered Index NCI_Invent_StockTransfers_2 on Invent_StockTransfers(BaseGrnID)

    Gocreate Nonclustered Index NCI_Invent_StockTransfers_3 on Invent_StockTransfers(TransferDate)Gocreate Nonclustered Index NCI_Invent_StockVerification_2 on Invent_StockVerification(VerDate)Gocreate Nonclustered Index NCI_Invent_StockVerification_Latest_1 on Invent_StockVerification_Latest(StoreEntry_Id) include (VerDate)Gocreate Nonclustered Index NCI_Invent_SubcoMatoutward_Tax_1 on Invent_SubcoMatoutward_Tax(DCNO)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_1 on Invent_SubcontractDetails(DcNo)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_2 on Invent_SubcontractDetails(SubconID)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_3 on Invent_SubcontractDetails(Billable)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_4 on Invent_SubcontractDetails(LocationID)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_5 on Invent_SubcontractDetails(AutoRefNo)Gocreate Nonclustered Index NCI_Invent_SubcontractDetails_6 on Invent_SubcontractDetails(poproductid)Gocreate Nonclustered Index NCI_Invent_SubcontractorAddn_1 on Invent_SubcontractorAddn(AF_ID)Gocreate Nonclustered Index NCI_Invent_WeightedAverage_1 on Invent_WeightedAverage(RawmatId)Gocreate Nonclustered Index NCI_Invent_WeightedAverage_2 on Invent_WeightedAverage(AvgDate)Gocreate Nonclustered Index NCI_Invent_WIN_1 on Invent_WIN(WINNo)

  • 8/6/2019 Scripts for SCPL1

    11/22

    Gocreate Nonclustered Index NCI_Invent_WIN_2 on Invent_WIN(WIN_Ref_No)Gocreate Nonclustered Index NCI_Invent_WIN_3 on Invent_WIN(SupId)Gocreate Nonclustered Index NCI_Invent_WINMaterialdetail_1 on Invent_WINMaterialdetail(WINNo)Gocreate Nonclustered Index NCI_Invent_WINMaterialdetail_2 on Invent_WINMaterialdetail(Rawmatid)Gocreate Nonclustered Index NCI_Invent_WINMaterialCharacteristics_1 on Invent_WINMaterialCharacteristics(WinID)Gocreate Nonclustered Index NCI_Sales_LRTransDetails_1 on Sales_LRTransDetails(TransporterID,LrNo)Gocreate Nonclustered Index NCI_Subcon_InwardMatAddn_1 on Subcon_InwardMatAddn(Af_ Id)

    Gocreate Nonclustered Index NCI_invent_min_12 on invent_min(issuetofg)Gocreate Nonclustered Index NCI_invent_minmaterial_8 on invent_minmaterial(AvlStockQty) where AvlStockQty>0Gocreate Nonclustered Index NCI_invent_Transactions_11 on invent_Transactions(csid) where csid>0Gocreate Nonclustered Index NCI_invent_Transactions_12 on invent_Transactions(minid) where minid>0Gocreate Nonclustered Index NCI_pdsubassly_1 on pdsubassly(pdid)Gocreate Nonclustered Index NCI_prodnforgingstagesaddn_1 on prodnforgingstagesaddn(Af_id)Gocreate Nonclustered Index NCI_prodnforgingstagescause_1 on prodnforgingstagescause(prodnforgingstagesid)Gocreate Nonclustered Index NCI_prodnforgingstagesEmployee_1 on prodnforgingstagesEmployee(prodnforgingstagesid)Gocreate Nonclustered Index NCI_prodnmatlostdetails_1 on prodnmatlostdetails(lostid)Gocreate Nonclustered Index NCI_Invent_prodnpacking_1 on prodnpacking(Packingid)Gocreate Nonclustered Index NCI_Invent_prodnpacking_2 on prodnpacking(Packingdate)Gocreate Nonclustered Index NCI_Invent_prodnpacking_3 on prodnpacking(previousstageids)Gocreate Nonclustered Index NCI_Invent_prodnpackinglocation_1 on prodnpackinglocation(Packingid)Gocreate Nonclustered Index NCI_prodnpackingpreid_2 on prodnpackingpreid(Packingid)Gocreate Nonclustered Index NCI_prodnpackingpreid_3 on prodnpackingpreid(preid,prewhoami)

  • 8/6/2019 Scripts for SCPL1

    12/22

    Gocreate Nonclustered Index NCI_loggeduserstatus_1 on loggeduserstatus(loginId)Gocreate Nonclustered Index NCI_sales_despatch_details_4 on sales_despatch_details(prodnstoreentryid)Gocreate Nonclustered Index NCI_sales_packworkingdetail_1 on sales_packworkingdetail(PackWorkingId)Gocreate Nonclustered Index NCI_sales_poaddn_1 on sales_poaddn(AF_ID)Gocreate Nonclustered Index NCI_workorder_5 on workorder(woId)Gocreate Nonclustered Index NCI_workorder_6 on workorder(podespatchID)Gocreate Nonclustered Index NCI_workorder_7 on workorder(mainparentwono)Gocreate Nonclustered Index NCI_sales_bom_1 on sales_bom(prodId,identification)Go

    create Nonclustered Index NCI_sales_bom_2 on sales_bom(type,typeprodid)Gocreate Nonclustered Index NCI_product_1 on product(die)Gocreate Nonclustered Index NCI_product_2 on product(prodactive)Gocreate Nonclustered Index NCI_prodnsubcontractordetails_8 on prodnsubcontractordetails(grouprefno)Gocreate Nonclustered Index NCI_prodnsubcontractordetails_9 on prodnsubcontractordetails(LocationID)Gocreate Nonclustered Index NCI_prodnsubcontractordetails_10 on prodnsubcontractordetails(ShopTravelNo)Gocreate Nonclustered Index NCI_prodnsubcontractordetails_11 on prodnsubcontractordetails(StockQty) where StockQty > 0Gocreate Nonclustered Index NCI_employee_3 on employee(resign)Gocreate Nonclustered Index NCI_employee_4 on employee(exclusiveuser)Gocreate Nonclustered Index NCI_invent_chargeslip_9 on invent_chargeslip(csreturned)Gocreate Nonclustered Index NCI_invent_chargeslip_10 on invent_chargeslip(dcno)Gocreate Nonclustered Index NCI_invent_chargeslip_11 on invent_chargeslip(grnno)Gocreate Nonclustered Index NCI_invent_dc_1 on invent_dc(dcno)Gocreate Nonclustered Index NCI_invent_dc_2 on invent_dc(dcdate)Gocreate Nonclustered Index NCI_invent_dc_3 on invent_dc(supid)Gocreate Nonclustered Index NCI_invent_dc_4 on invent_dc(locationid)Gocreate Nonclustered Index NCI_invent_dcmaterial_1 on invent_dcmaterial(dcno)Gocreate Nonclustered Index NCI_invent_dcmaterial_2 on invent_dcmaterial(despatchid)

  • 8/6/2019 Scripts for SCPL1

    13/22

    Gocreate Nonclustered Index NCI_invent_dcmaterial_3 on invent_dcmaterial(dcid)Gocreate Nonclustered Index NCI_invent_dcmaterial_4 on invent_dcmaterial(csid)Gocreate Nonclustered Index NCI_invent_grn_13 on invent_grn(Grn_DcNo)Gocreate Nonclustered Index NCI_invent_grnmaterialdetail_18 on invent_grnmaterialdetail(identification) include (rawmatid)Gocreate Nonclustered Index NCI_invent_grnmaterialdetail_19 on invent_grnmaterialdetail(isdummy) include (LinkedShippingDCId)Gocreate Nonclustered Index NCI_ProdnsettingDetails_1 on ProdnsettingDetails(prodnforgingstagesid)Gocreate Nonclustered Index NCI_ProdnsettingDetails_2 on ProdnsettingDetails(csno)Gocreate Nonclustered Index NCI_sales_bom_3 on sales_bom(identification)

    Gocreate Nonclustered Index NCI_product_3 on product(InternalPartNo)Gocreate Nonclustered Index NCI_product_4 on product(ProdName)Gocreate Nonclustered Index NCI_sales_prodaddn_1 on sales_prodaddn(AF_ID)Gocreate Nonclustered Index NCI_productprocess_1 on productprocess(Prodid)Gocreate Nonclustered Index NCI_prodnforgingstagessubassly_1 on prodnforgingstagessubassly(ProdnForgingStagesID)Gocreate Nonclustered Index NCI_prodnforgingstagessubassly_2 on prodnforgingstagessubassly(PreviousStagesID,WHOAMI)Gocreate Nonclustered Index NCI_prodnsubcontractorsubassly_1 on prodnsubcontractorsubassly(PreviousStagesID,WHOAMI)Gocreate Nonclustered Index NCI_prodnsubcontractorsubassly_2 on prodnsubcontractorsubassly(DcNo)Gocreate Nonclustered Index NCI_prodnsubcontractorsubassly_3 on prodnsubcontractorsubassly(SubConDetId)Gocreate Nonclustered Index NCI_workorder_8 on workorder(WOPDID)Gocreate Nonclustered Index NCI_productmaster_changes_1 on productmaster_changes(ProdID)Gocreate Nonclustered Index NCI_prodnmatdetails_3 on prodnmatdetails(RecoveredProdnID,RecoveredProdnWHOAMI)Gocreate Nonclustered Index NCI_prodnforgingstagesscraptypes_1 on prodnforgingstagesscraptypes(prodnforgingstagesid)Gocreate Nonclustered Index NCI_prodnforgingstagesscraptypes_2 on prodnforgingstagesscraptypes(scrapid)GoCREATE NONCLUSTERED INDEX [NCI_Purchase_7] ON [dbo].[Purchase] ([postatus])GoCREATE NONCLUSTERED INDEX [NCI_processdocument_4] ON [dbo].[ProcessDocument] ([

  • 8/6/2019 Scripts for SCPL1

    14/22

    QStatus]) INCLUDE ([GradeID],[Route])GoCREATE NONCLUSTERED INDEX [NCI_prodnforgingstages_16] ON [dbo].[ProdnForgingStages] ([WHOAMI])GoCREATE NONCLUSTERED INDEX [NCI_invent_Transactions_13] ON [dbo].[Invent_Transactions] ([TransnType]) INCLUDE ([Description])Go

    create NONCLUSTERED index NcI_Ppc_ProdnStatusChanges-ProdnForgingStagesID Ppc_ ProdnStatusChanges ()Gocreate nonclustered index NCI_Report_RowColPositions_RepID on Report_RowColPositions()GoCreate NonClustered Index NCI_LoginStatus_LoginStatusID on LoginStatus()Gocreate Nonclustered Index NCI_Sales_CustSettingDetails_3 on Sales_CustSettingDetails()

    Gocreate nonclustered index NCI_QcSampleInspection_OtherInspId on QcSampleInspection(OtherInspId)Gocreate nonclustered index NCI_GradeContents_GradeId on GradeContents(GconId) include (GradeId)Gocreate nonclustered index NCI_ProdnIdleTimeReasons_ProdnForgingStagesID on ProdnIdleTimeReasons(ProdnForgingStagesID)Gocreate nonclustered index NCI_ProdnIdleTimeReasons_ProdnForgingStagesID on ProdnIdleTimeReasons(ProdnForgingStagesID)Gocreate nonclustered index NCI_Hrm_ShiftRotation_Id on Hrm_ShiftRotation (Id)Gocreate nonclustered index NCI_Qc_ChemComp_GrnId on Qc_ChemComp(GrnId)Gocreate nonclustered index NCI_Hrm_AccRegChanges_EmpId on Hrm_AccRegChanges (EmpId)Gocreate nonclustered index NCI_GradeContentsForCust_GConId on GradeContentsForCust(GConId)Gocreate nonclustered index NCI_GradeContentsForCust_GConId on GradeContentsForCust(GConId)Gocreate nonclustered index NCI_maintworkers_tmid on maintworkers(tmid)Gocreate nonclustered index NCI_Maintenance_MaintenanceID on Maintenance(MaintenanceID)Gocreate nonclustered index NCI_MaintBreakdown_BDID on MaintBreakdown(BDID)

    ----------------LedgerDb

    --create Nonclustered Index NCI_Accounts_1 on Accounts(ID)--Go--create Nonclustered Index NCI_Accounts_2 on Accounts(OlevelID,Active) include(accountcode,name,id)--Go--create Nonclustered Index NCI_Accounts_3 on Accounts(Active)

  • 8/6/2019 Scripts for SCPL1

    15/22

    --Go--create Nonclustered Index NCI_Accounts_4 on Accounts(AccountID)--Go--create Nonclustered Index NCI_Adjustment_1 on Adjustment(TransactionID)--Go--create Nonclustered Index NCI_Adjustment_2 on Adjustment(AdTransactionID)--Go--create Nonclustered Index NCI_Transactions_1 on Transactions(AccountID,DrCr,TrTypeNo,LocationID,Approved) include (Amount)--Go--create Nonclustered Index NCI_Transactions_3 on Transactions(Approved)--Go--create Nonclustered Index NCI_Transactions_4 on Transactions(CheckNo)--Go--create Nonclustered Index NCI_Transactions_5 on Transactions(CostCentreID)--Go--create Nonclustered Index NCI_Transactions_6 on Transactions(DrCr)--Go--create Nonclustered Index NCI_Transactions_7 on Transactions(Edited)

    --Go--create Nonclustered Index NCI_Transactions_9 on Transactions(LocationID)--Go--create Nonclustered Index NCI_Transactions_10 on Transactions(TaxID)--Go--create Nonclustered Index NCI_Transactions_11 on Transactions(TransactionDate)--Go--create Nonclustered Index NCI_Transactions_12 on Transactions(TransactionNumber)--Go--create Nonclustered Index NCI_Transactions_13 on Transactions(TrTypeNo)--Go--create Nonclustered Index NCI_Transactions_14 on Transactions(AccountID,VoucherNo) where ([voucherno]>(0))--Go--create Nonclustered Index NCI_TransCostDistribution_1 on TransCostDistribution(TransactionId)--Go--create Nonclustered Index NCI_TransCostDistribution_2 on TransCostDistribution(Costdistrid,Seltype)--Go--create Nonclustered Index NCI_ACC_Rebate_Claim_1 on ACC_Rebate_Claim(GRNNo) include(taxaccountid)--Go--create Nonclustered Index NCI_Bank_AutoEntries_2 on Bank_AutoEntries(AccountId) include(transactionDate)

    --------------------ReportDb

    --create Nonclustered Index NCI_StdReport_1 on StdReport(stdReportId)--Go--create Nonclustered Index NCI_stdReportAddFilterControls_1 on stdReportAddFilterControls(stdReportId)--Go--create Nonclustered Index NCI_stdReportAddFilterControls_2 on stdReportAddFilterControls(stdReportId,Controls,FiltersCriteria)--Go--create Nonclustered Index NCI_stdReportAddFilterStrings_1 on stdReportAddFilterStrings(stdReportId)--Go--create Nonclustered Index NCI_stdReportAddFilterStrings_2 on stdReportAddFilte

  • 8/6/2019 Scripts for SCPL1

    16/22

    rStrings(FilterStringID)--Go--create Nonclustered Index NCI_StdReportCols_1 on StdReportCols(stdReportId,SettingType)--Go--create Nonclustered Index NCI_StdReportRights_1 on StdReportRights(LoginID,stdReportId)--Go--create Nonclustered Index NCI_StdReportSub_1 on StdReportSub(stdReportId,runType)--Go--create Nonclustered Index NCI_StdFormatSub_1 on StdFormatSub(StdFormatId)

    ==============================================================--Top 50 Mos Expensive QueriesSELECT TOP 50 SUBSTRING(qt.text, (qs.statement_start_offset/2)+1,

    ((CASE qs.statement_end_offsetWHEN -1 THEN DATALENGTH(qt.text)

    ELSE qs.statement_end_offset

    END - qs.statement_start_offset)/2)+1),qs.execution_count,qs.total_logical_reads, qs.last_logical_reads,qs.min_logical_reads, qs.max_logical_reads,qs.total_elapsed_time, qs.last_elapsed_time,qs.min_elapsed_time, qs.max_elapsed_time,qs.last_execution_time,qp.query_planFROM sys.dm_exec_query_stats qsCROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qtCROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qpWHERE qt.encrypted=0ORDER BY qs.total_logical_reads DESC

    --Missing IndexesSELECT mig.*, statement AS table_name,

    column_id, column_name, column_usageFROM sys.dm_db_missing_index_details AS midCROSS APPLY sys.dm_db_missing_index_columns (mid.index_handle)INNER JOIN sys.dm_db_missing_index_groups AS mig ON mig.index_handle = mid.index

    _handleORDER BY mig.index_group_handle, mig.index_handle, column_id;GO

    ---Remove UnUsed Indexesselect a.database_id,a.index_id,i.name,a.user_seeks,a.user_scans,a.user_lookups,a.object_id from sys.dm_db_index_usage_stats ainner join sys.indexes i on a.object_id=i.object_id

    -- Ensure a USE statement has been executed first.SET QUOTED_IDENTIFIER ON;SET NOCOUNT ON;DECLARE @objectid int;DECLARE @indexid int;DECLARE @partitioncount bigint;DECLARE @schemaname nvarchar(130);DECLARE @objectname nvarchar(130);DECLARE @indexname nvarchar(130);DECLARE @partitionnum bigint;DECLARE @partitions bigint;

  • 8/6/2019 Scripts for SCPL1

    17/22

    DECLARE @frag float;DECLARE @pagecount bigint;DECLARE @command nvarchar(4000); -- Conditionally select tables and indexes from the sys.dm_db_index_physical_stats function-- and convert object and index IDs to names.SELECT

    object_id, index_id, partition_number, page_count, avg_fragmentation_in_percent --AS fragINTO #work_to_doFROM sys.dm_db_index_physical_stats (11, NULL, NULL , NULL, 'LIMITED')WHERE avg_fragmentation_in_percent > 10.0 AND index_id > 0;

    -- Declare the cursor for the list of partitions to be processed.DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;

    -- Open the cursor.OPEN partitions;

    -- Loop through the partitions.WHILE (1=1)

    BEGIN;FETCH NEXT

    FROM partitionsINTO @objectid, @indexid, @partitionnum,@pagecount,@frag;

    IF @@FETCH_STATUS < 0 BREAK;SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)FROM sys.objects AS oJOIN sys.schemas as s ON s.schema_id = o.schema_idWHERE o.object_id = @objectid;SELECT @indexname = QUOTENAME(name)FROM sys.indexesWHERE object_id = @objectid AND index_id = @indexid;SELECT @partitioncount = count (*)FROM sys.partitionsWHERE object_id = @objectid AND index_id = @indexid;

    -- 30 is an arbitrary decision point at which to switch between reorganizing andrebuilding.

    IF @frag < 30.0 and @pagecount>1000SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname

    + N'.' + @objectname + N' REORGANIZE WITH ( LOB_COMPACTION = ON )';IF @frag >= 30.0 and @pagecount>1000

    SET @command = N'ALTER INDEX ' + @indexname + N' ON ' + @schemaname+ N'.' + @objectname + N' REBUILD PARTITION = ALL WITH ( PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, ONLINE= OFF, SORT_IN_TEMPDB = OFF )';

    IF @partitioncount > 1SET @command = @command + N' PARTITION=' + CAST(@partitionnum AS nva

    rchar(10));EXEC (@command);PRINT N'Executed: ' + @command;

    END;

    -- Close and deallocate the cursor.CLOSE partitions;DEALLOCATE partitions;

    -- Drop the temporary table.

  • 8/6/2019 Scripts for SCPL1

    18/22

    DROP TABLE #work_to_do;GO

    --select DB_ID('IcSoftLedger09')---8--select DB_ID('BizSoft')----------11--select DB_ID('IcSoft')-----------7--select DB_ID('IcSoftReport')-----9--select * from #work_to_do where (page_count > 1000 ) order by page_count desc--After rebuilding check out the fragmentation percentage here--select * from sys.dm_db_index_physical_stats (11, NULL, NULL , NULL, 'LIMITED')--where object_id=1635536910 and index_id=1

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

    -- Otto R. Radke - http://ottoradke.com-- Info: T-SQL script to shrink a database's transaction log. Just set the-- database name below and run the script and it will shrink the-- transaction log.-------------------------------------------------------------------------------------------------------------------------------------------------------------- Update the line below with the name of the database who's transaction-- log you want to shrink.------------------------------------------------------------------------------USE icsoft-------------------------------------------------------------------------------- Don't change anything below this line.------------------------------------------------------------------------------GO-- Declare variablesDECLARE @SqlStatement as nvarchar(max)DECLARE @LogFileLogicalName as sysname-- Alter the database to simple recoverySET @SqlStatement = 'ALTER DATABASE ' + DB_NAME() + ' SET RECOVERY SIMPLE'EXEC ( @SqlStatement )-- Make sure it has been alteredSELECT [name], [recovery_model_desc] FROM sys.databases WHERE [name] = DB_NAME()-- Set the log file name variableSELECT @LogFileLogicalName = [Name] FROM sys.database_files WHERE type = 1-- Shrink the logfileDBCC Shrinkfile(@LogFileLogicalName, 1)-- Alter the database back to FULLSET @SqlStatement = 'ALTER DATABASE ' + DB_NAME() + ' SET RECOVERY FULL'EXEC ( @SqlStatement )-- Make sure it has been changed back to fullSET @SqlStatement = 'SELECT [name], [recovery_model_desc] FROM ' + DB_NAME() + '.sys.databases WHERE [name] = ''' + DB_NAME() + ''''EXEC ( @SqlStatement )

  • 8/6/2019 Scripts for SCPL1

    19/22

    Negative Unused SpaceI wrote simple script to check space used by tables:

    CREATE TABLE #SpaceUsed(TableName NVARCHAR(128),NoOfRows INT,Reserved NVARCHAR(18),Data NVARCHAR(18),Index_Size NVARCHAR(18),Unused NVARCHAR(18))GOsp_msforeachtable "INSERT INTO #SpaceUsed EXEC sp_spaceused '?'"

    SELECT * FROM #SpaceUsed

    SELECT

    CAST(Sum(CAST(Replace(Reserved,' KB','') AS INT)) AS NVARCHAR) + ' KB' AS TotalReserved,CAST(Sum(CAST(Replace(Data,' KB','') AS INT)) AS NVARCHAR) + ' KB' AS TotalData, CAST(Sum(CAST(Replace(Index_Size,' KB','') AS INT)) AS NVARCHAR) + ' KB' AS TotalIndex_Size,CAST(Sum(CAST(Replace(Unused,' KB','') AS INT)) AS NVARCHAR) + ' KB' AS TotalUnusedFROM #SpaceUsed

    DROP TABLE #SpaceUsed

    ResourceWaits:

    Resource WaitsSelect signal_wait_time_ms=sum(signal_wait_time_ms),'%signal (cpu) waits' = cast(100.0 * sum(signal_wait_time_ms) /sum (wait_time_ms) as numeric(20,2)),resource_wait_time_ms=sum(wait_time_ms - signal_wait_time_ms),'%resource waits'= cast(100.0 * sum(wait_time_ms -signal_wait_time_ms) / sum (wait_time_ms) as numeric(20,2))From sys.dm_os_wait_stats

    The Results of the query are the following:signal_wait_time_ms: 518816%signal (cpu) waits: 13.33resource_wait_time_ms: 3373229%resource waits: 86.67

    FindingUnusedIndexes:

    The following Transact-SQL will return the indexes (with associated tables) thatare likely candidates for deletion.

    use [wcAdmin]

  • 8/6/2019 Scripts for SCPL1

    20/22

    goSELECT TableName = OBJECT_NAME(s.[object_id])

    ,IndexName = i.name,user_updates,system_updates

    FROM sys.dm_db_index_usage_stats sINNER JOIN sys.indexes i ON s.[object_id] = i.[object_id]

    AND s.index_id = i.index_idWHERE OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0 -- Only wcadmin defined.

    AND user_seeks = 0AND user_scans = 0AND user_lookups = 0AND i.name IS NOT NULL -- Ignore HEAP indexes.

    ORDER BY user_updates DESC

    ErrorLogs:

    CREATE PROC [sys].[sp_readerrorlog](@p1 INT = 0,@p2 INT = NULL,@p3 VARCHAR(255) = NULL,@p4 VARCHAR(255) = NULL)

    ASBEGIN

    IF (NOT IS_SRVROLEMEMBER(N'securityadmin') = 1)BEGIN

    RAISERROR(15003,-1,-1, N'securityadmin')RETURN (1)

    END

    IF (@p2 IS NULL)EXEC sys.xp_readerrorlog @p1

    ELSEEXEC sys.xp_readerrorlog @p1,@p2,@p3,@p4

    END

    This statement returns all of the rows from the 6th archived error log.EXEC sp_readerrorlog 6

    This returns just 8 rows wherever the value 2005 appears.EXEC sp_readerrorlog 6, 1, '2005'

    This returns only rows where the value '2005' and 'exec' exist.EXEC sp_readerrorlog 6, 1, '2005', 'exec'

    ===========================================declare @indexinfotemp table(index_name varchar(100),index_description varchar(1000),index_keys varchar(1000)

  • 8/6/2019 Scripts for SCPL1

    21/22

    )declare @indexinfo table(Table_name sysname,index_name varchar(100),index_description varchar(100),index_keys varchar(1000))declare @tables table(row_id int identity(1,1),tablename sysname)declare @max_row intdeclare @currentrow intdeclare @cuuenttable sysnameinsert into @tables select distinct t.name from sys.indexes i inner join sys.tables t on i.object_id =t.object_idwhere i.name is not nullselect @max_row =@@ROWCOUNT ,@currentrow =1while @currentrow @max_rowbeginselect @cuuenttable =tablename from @tables where row_id=@currentrowinsert into @indexinfotemp exec sp_helpindex @cuuenttable

    insert into @indexinfo (Table_name,index_name,index_description,index_keys) select @cuuenttable ,index_name,index_description,index_keys from @indexinfotempdelete From @indexinfotemp set @currentrow = @currentrow+1end

    select count(Table_name) as CountOfIndexes ,Table_name from @indexinfo group byTable_name having count(Table_name)> 5 order by CountOfIndexes

    ==============================================================--GetAllTableSizes

    CREATE PROCEDURE GetAllTableSizesASDECLARE @TableName VARCHAR(100) --For storing values in the cursor

    --Cursor to get the name of all user tables from the sysobjects listingDECLARE tableCursor CURSORFORselect [name]from dbo.sysobjectswhere OBJECTPROPERTY(id, N'IsUserTable') = 1FOR READ ONLY

    --A procedure level temp table to store the resultsCREATE TABLE #TempTable(

    tableName varchar(100),numberofRows numeric,reservedSize varchar(50),dataSize varchar(50),indexSize varchar(50),unusedSize varchar(50)

    )

    --Open the cursorOPEN tableCursor

    --Get the first table name from the cursor

  • 8/6/2019 Scripts for SCPL1

    22/22