Solved

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

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

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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…
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.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

813 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

10 Experts available now in Live!

Get 1:1 Help Now