Solved

10774: index clustered is better?? always?

Posted on 2015-02-21
1
85 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 500 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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 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