[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

10774: index clustered is better?? always?

Posted on 2015-02-21
1
Medium Priority
?
92 Views
Last Modified: 2015-02-21
Hi experts, because in this example is better to create a clustered index

--1. Crear una tabla temporal cargada con registros, para ello, ejecutar el siguiente
use AdventureWorks
GO
      Select * into
      PODTemp
      from Purchasing.PurchaseOrderDetail

--2. Para evaluar la cantidad de scans, logical reads, phisical reads, etc., ejecutar el
set statistics io on
      select * from PODTemp
      where productid between 500 and 510
      order by productid
set statistics io off
      --Table 'PODTemp'. Scan count 1, logical reads 78,

--3. Crear un índice nonclustered.
Create Nonclustered Index IDX1 on dbo.PODTemp (ProductId)

--4
--Volver a ejecutar el script del paso 2 y guardar la información en el tab messages.
set statistics io on
      select * from PODTemp
      where productid between 500 and 510
      order by productid
set statistics io off
--Table 'PODTemp'. Scan count 1, logical reads 78,

--5
--Ahora, se elimina y se creamos un índice clustered, para lo cual se ejecutan las siguientes sentencias (en el orden como figuran en cada fila)
      Drop Index IDX1 on dbo.PODTemp
      
      Create Clustered Index IDX1 on dbo.PODTemp (ProductId)

--6
set statistics io on
      select * from PODTemp
      where productid between 500 and 510
      order by productid
set statistics io off

--Table 'PODTemp'. Scan count 1, logical reads 8,
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 40623259
>where productid between 500 and 510
this is what is called a "range query"

a clustered index on that field will organise the records with the same values together (in the same page blocks), and hence such range queries will work "best" (least reads) when supported by such a index.

this also is good when you have several records with the same value (like a invoice table with the clustered index on customer id )
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question