|
-
Apr 14th, 2006, 08:21 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] SQL Server, Clustered Index
Table, with 18M records, has a compound PK of ORDER_NUM and ORDER_LINE_NUM. (Every order can have many lines)
There are many time that I will need to query for the lines of a single order, so am considering a clustered index.
My questions is:
Do I make the index associated witht the compound PK clustered or should I have a seperate clustering index which only includes the ORDER_NUM column?
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Apr 14th, 2006, 11:33 AM
#2
Re: SQL Server, Clustered Index
Using the same columns in a clustered and non-clustered index is a waste of disk space because all non-clustered indexes contain the clustered Index. Plus, I doubt the non-clustered index would ever be used by sql server.
If the most often used query looks something like
Select * From TableName Where Order_Num = 12345 Order By Order_Line_Num
Then I would Cluster the PK.
However, how often does the Order_Line_Num column change (I never understood why detail data contains a "line number")? Does your application allow users to change line numbers. If a line number is deleted do you have to re-set all other line numbers.
If the answer is "often", then using the Order_Line_Num in a Clustered Index would not be a good idea. When a change to a clustered index causes a new sort order all other indexes pointing to the original clustered index are updated as well.
-
Apr 14th, 2006, 11:36 AM
#3
Thread Starter
Frenzied Member
Re: SQL Server, Clustered Index
 Originally Posted by brucevde
...how often does the Order_Line_Num column change (I never understood why detail data contains a "line number")? Does your application allow users to change line numbers. If a line number is deleted do you have to re-set all other line numbers.
If the answer is "often", then using the Order_Line_Num in a Clustered Index would not be a good idea. When a change to a clustered index causes a new sort order all other indexes pointing to the original clustered index are updated as well.
The line num can never change, this is warehousing/reporting app, not the prime system, so the data never changes.
I will cluster on the PK.
Thanks again
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|