?
Solved

What column to use for clustered index?

Posted on 2013-06-29
2
Medium Priority
?
428 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
[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
2 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 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 1000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Learn about cloud computing and its benefits for small business owners.
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

719 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