Solved

What column to use for clustered index?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
The reason that corporations and businesses use Windows servers is because it supports custom modifications to adapt to the business and what it needs. Most individual users won’t need such powerful options. Here I’ll explain how you can enable Wind…
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

636 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