We have a Transactional Media table that contains a clustered primary key of 4 columns. RevenueCentreID, DateOfSale, MediaItemID and SaleTypeID. It also contains a quantity column and amount column.
Most our queries will be selecting Revenue Centres for a date range for a certain media item. We hardly ever use the SaleTypeID.
Would it be better to create an index on RevenueCentreID, DateOfSale, MediaItemID or a covering index on those three columns?
The RevenueCentreID and RevenueCentreID are foreign keys to a RevenueCentres Table and MediaItems table respectively. They will almost always be joined to when running queries.
A typical query will look something like the one below:
Select
RevenueCentreID,
MediaItemID,
DateOfSale,
SUM(Quantity)Quantity,
SUM(Amount)Amount
From
Media m
Inner Join RevenueCentres rc on m.RevenueCentreID = rc.RevenueCentreID
Inner Join MediaItems mi on m.MediaItemID = mi.MediaItemID
Inner Join MediaCategories mc on mi.MediaCategoryID = mc.MediaCategoryID
Where
rc.ProfitCentreID = 1
And mc.MediaCategoryID = 1
And (DateOfSale Between '20090713' and '20090719')
Group By
DateOfSale,
RevenueCentreID,
MediaItemID
Any suggestions would be appreciated…