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
Solved

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

Posted on 2011-02-21
5
402 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 143

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

791 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