Solved

What column to use for clustered index?

Posted on 2013-06-29
2
420 Views
Last Modified: 2013-07-01
Hello,

I am struggling with the question which column to use for my clustered index? So far, if I have the table:

id, firstname, lastname

I always automatically gave identity(1,1) and clustered index (primary key) on that one. But - is this always correct? I practically never seek by id. There are always some other columns that I usually search on. In above scenario: if I search by firstname - does clustered index on id has any impact on my query? Or it would be the same if I just left whole table as a heap? Same goes if I use my search by lastname ?

What about this table:

id, ssid, firstname, lastname

Is there a point to have id column at all in the table? Or is it better to put id out and have clustered index on ssid?


cherrs, F
0
Comment
Question by:AntonioRodrigo
2 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 39287063
a clustered index dictate the physical sequence of the data in a table.

if your clustered index is by lastname and you do a "select * where lastname between 'm' and 'p' order by lastname", it will be optimal.

but if you insert a lot of data, you will get a lot of page split which will reduce performance

it is sometimes difficult to find the sweet spot/index
0
 
LVL 16

Accepted Solution

by:
EvilPostIt earned 250 total points
ID: 39289261
It depends on your entire database to be honest, if there are relational tables then this is a good reason as while it isn't data that the user would see it is still used quite a lot to match rows.

Your key should be unique though as if it isnt the row will be made larger as a field called a unqueifier will be added to the page.

As per emoreau's comments you should think about how the data is going to be used, inserted, deleted in the future as if you choose the position now it could cause you troubles down the road!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server 2012 R2 Hyper 12 39
My Server Turned Off 6 44
How come this XML node is not read? 3 27
Shared files and folders migration 2 26
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
OfficeMate Freezes on login or does not load after login credentials are input.
In this Micro Tutorial viewers will learn how to restore single file or folder from Bare Metal backup image of their system. Tutorial shows how to restore files and folders from system backup. Often it is not needed to restore entire system when onl…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

763 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