?
Solved

Most documentation says to put the clustered index on the Primark Key....

Posted on 2011-02-21
5
Medium Priority
?
409 Views
Last Modified: 2012-05-11
I asked  a question last week.. but I am not sure I successfully put my idea across(http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_26831283.html)

I would like to re introduce the question, but this time I have added more sources.

Most documentation says to put the clustered index on the Primark Key....

However, after reading SQL Server 2008 Query Performance Tuning Distilled (Apress) page 118 it suggests putting a unique non-clustered index on the Primary Key.

This idea is also mentioned in SQL Server 2005 Performance Tuning (Wrox) page 234 and Inside Microsoft SQL Server 2005 Query Tuning and Optimization (Microsoft) 232.

Does anybody have any comments on not using the clustered index on an IDENTITY(1,1) INT Primary Key column?

I am using sql 2005/2008..... It would be also interesting if a different approach exists for other datase engines?

Here are a number of links which discuss the idea.
http://www.mssqlcity.com/Tips/tipInd.htm - See section beginning 'Avoid creating a clustered index based on an incrementing key'.

http://www.devx.com/tips/Tip/5648

http://books.google.co.uk/books?id=CD6Y4wAdQpwC&printsec=frontcover&dq=sql+server+2008+query+performance+tuning+distilled&hl=en&ei=uD5gTdnJE4yb4Aau-LDFCQ&sa=X&oi=book_result&ct=result&resnum=1&ved=0CDsQ6AEwAA#v=onepage&q&f=false

http://bytes.com/topic/sql-server/answers/81459-why-cluster-primary-key
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/cf9121b2-38e0-4735-b765-4eab91bb443b/

http://stackoverflow.com/questions/581505/is-primary-key-always-clustered

http://www.sqlservercentral.com/Forums/Topic1048687-391-1.aspx

http://www.sqldev.org/transactsql/which-index-is-better-64091.shtml
0
Comment
Question by:Mr_Shaw
[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
  • 3
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 34941881
well, there are 2 things:
* if you have a table where only the primary key is indexed, it shall be a clustered index
* if you have a table where other indexes exist besides the primary key, it shall not be the primary key that is the clustered index.

the reasoning behind is this:
* a table without a clustered index is managed like a heap, which will result in eventually lots of space wasted if there is lots of updates and deletes on the table
* clustered indexes are best to support range queries (BETWEEN, >= , < etc ... )

short conclusion:
* if you have a very small table, or a table that changes very rarely, you would not really need a clustered index, but it won't hurt neither
* if you have a large table, or a table with lots of changes (update/delete), a clustered index shall exist on the table, but usually, it won't be the primary key unless that is the only index on the table
0
 

Author Comment

by:Mr_Shaw
ID: 34941912
If my Primary Key is on a column with an INT Identity Datatype will this ensure that row INSERTs are added in order to the data pages....
0
 

Author Comment

by:Mr_Shaw
ID: 34941917
It seems that most of the DB world put clustered index on the Primary Key...
0
 

Author Closing Comment

by:Mr_Shaw
ID: 34941970
thanks..
0
 
LVL 22

Expert Comment

by:dportas
ID: 35214017
Most tables will benefit from a clustered index but it doesn't necessarily make sense to say that a primary key should be the clustered index. It depends on what the primary key is and how it is used.

Just saying that something is the primary key doesn't really tell us enough to determine whether it should be clustered or not. For example a uniqueidentifier column generally is not a good choice for a clustered index key, whether the uniqueidentifier is a primary key or not.

Choosing keys and indexes are separate concerns. Don't assume that one must follow from the other.

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

752 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