I have a huge (millions of rows) table that contains the following columns:
[When] datetime2(0),
[What] tinyint,
[Who] bigint
It's basically a table of events ('What') that happened to various entities ('Who') at a time ('When'). There are about 10 different values for 'What' - it is an enumeration. There are about 10,000 values for 'Who' at the moment.
I want to be able to query this table, to ask whether something happened to a one or more entities between a certain time. For instance, did [What = 0, 1, 2, 3] happen to [Who = 0, 1, 2, 3] between [When = '2012-10-01' to '2012-11-01'].
I'm looking for advice on how best to index this table. I'm fairly sure a composite index is the way to go, but I'm unsure of the exact configuration. For instance, what should the column order be? I've read that the 'most selective' columns should go to the left, which I think in this case would be [When], [Who], [What]. Is this correct?
Sorry if this question seems vague, but I'd be grateful for any input. I'm using SQL Server 2012.