none
What is the most effective declaration for the PRIMARY KEY CLUSTERED in SQL table RRS feed

  • Question

  • Hello,

    I wonder something about the PRIMARY KEY CLUSTERED for a ceratain scenario.
    I am not sure what would be the Fastest way to return the information I want.

    I will describe what I want to return from a table (See Attached image of table)

    1. The table exist of 3000 rows. The table only exists of Dates within 1 month. So it is 30 or 31 days. DateTimes like: 2010-01-03 17:45:00
    2. _DayNr column tells which day it is in the date. 3 for 2010-01-03 17:45:00
    3. It exists 1570 _featureNbr for EACH _DateTime. So for example: 
       2010-01-03 17:45:00 have 1570 _FeatureNbr and so on.

    Now is my task this. I want to return ALL _FeatureNbr for each of the 3000 
    DateTimes like: 2010-01-03 17:45:00.

    So I wonder what would be the most effective declaration for the PRIMARY KEY CLUSTERED?

    Shouldn't I just use _DateTime as the first one and _FeatureNbr as the second one?
    CONSTRAINT [PK_table20101] PRIMARY KEY CLUSTERED ([_DateTime] ASC, [_FeatureNbr]),

    Or is it faster to use _DayNr first like this?
    CONSTRAINT [PK_table20101] PRIMARY KEY CLUSTERED ([_DayNr] ASC, [_DateTime] ASC, [_FeatureNbr]),

    Or should I do this in a different way. I am not 100% sure in what way I should think when declaring
    those most effectively?

    Thank you!




    • Edited by Silvers11 Sunday, October 18, 2020 9:26 PM
    Sunday, October 18, 2020 9:22 PM

Answers

  • Hello,

    As this is not a C# question but SQL-Server related use the following new forum.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Silvers11 Sunday, October 18, 2020 10:29 PM
    Sunday, October 18, 2020 10:10 PM
    Moderator

All replies

  • Hello,

    As this is not a C# question but SQL-Server related use the following new forum.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Silvers11 Sunday, October 18, 2020 10:29 PM
    Sunday, October 18, 2020 10:10 PM
    Moderator
  • Thank you Kareninstructor,

    I didn't know that. I will use that forum for that then.

    Sunday, October 18, 2020 10:29 PM