Results 1 to 3 of 3

Thread: [RESOLVED] SQL Server, Clustered Index

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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.

  3. #3

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: SQL Server, Clustered Index

    Quote 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
  •  



Click Here to Expand Forum to Full Width