Solved

What column to use for clustered index?

Posted on 2013-06-29
2
417 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 69

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

What to do when Windows Update is not working correctly? What tools can I use to detect the cause of the malfunction problem? What does this numeric error code mean? These and other questions that you have been asking in the past are answered here (…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
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…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now