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

  • Thread starter Thread starter Silvers11
  • Start date Start date
S

Silvers11

Guest
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!


1622316.png

Continue reading...
 
Back
Top