SQLDancyLeeSummaryTableIndexSARGStoreProcedureExecutionPlanSQL2000ArchitectureTablePrimaryKey.Alwayscreateaprimarykey.AvoidcreateprimarykeyonAttribute.NULLIndexIndexBasicClusteredIndexNon-ClusteredIndexIndexBasicAllSQLServerIndexesAreOrganizedAsB-Trees.MultipleIndexesCanBeUsedOnASingleTable.WithNoIndexes,ATableMustBeScanned.ClusteredIndexClusteredIndexDataorderbyClusteredIndexOnlyoneClusteredIndexinonetableTheleaflevelcontainsthedatapages.theclusteredkeyisduplicatedineverynon-clusteredindexrow.ClusteredIndexUniqueIfNon-Unique,RIDwillautoaddedNarrowStaticEver-increasingTheImpactofClusteredIndexChangeRecordRelocationEveryNon-ClusteredIndextobemodifiedCausepagesplitandfragmentationWasteTimeGoodClusteredIndexEver-IncreasingIdentitycolumn,IntorBigIntEver-IncreasingDatecolumnfollowedbyIdentitycolumnEver-IncreasingGUIDNon-ClusteredIndexNon-ClusteredIndexTheLeafLevelContainsaBookmark:ClusteredIndex.RID.EfficientWhenSearchingForASingleRow.95%performanceissuecanbefixedwithcorrectindex.Indexlikesalt.StoreProcedureASeriesofSQLstatements.Pre-compiled.Lownetworktraffic.SP_versusUSP_.SARG(SearchArgument)columnoperatorvalue.valueoperatorcolumn.Operatormustbeoneof=,,=,=.Somenon-SARGcanbeconverted.QueryOptimizationSELECT*versusSELECTcolumn1,column2,column3,….NeverreturnmoredatathatyoureallyneedUNIONversusUNIONALLLIKE‘%A’versusLIKE‘A%’DATEDIFF…ExecutionPlanTableScanIndexSeekClusteredIndexSeekClusteredIndexScan,aslikeTableScanPhysicaloperation:Thisistheoperatorusedbythequeryoptimizerforthisstep.Oneexamplewouldbeanestedloop.Logicaloperation:Isusuallythesameasthephysicaloperator.Whendifferent,thisrepresentsakeywordinthequery.OneexamplewouldbeINNERJOIN.Rowcount:Thisisthenumberofrowsfetchedbythisstepandpassedtothenextstep.Estimatedrowsize:Thisistheestimatedrowsizepassedontothenextstep.I/Ocost:ThisistheestimatedcostforallI/Oactivityforastep.Thelowerthisnumberisthebetter.CPUcost:ThisistheestimatedcostforallCPUactivity.Numberofexecutes:Isthenumberoftimesthestepwasexecuted.Cost:Isthecostforthestepbeingviewed.Thelowerthisnumberisthebetter.Subtreecost:Isthecostofthestepbeingviewedandallprevioussteps.SQLProfilerBooksOnline