Solved

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

Posted on 2011-02-21
5
396 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
  • 3
5 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

747 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

11 Experts available now in Live!

Get 1:1 Help Now