While studying for the 70-433 exam I noticed you can create a covering index in one of the following two ways.
CREATE INDEX idx1 ON MyTable (Col1, Col2, Col3)
— OR —
CREATE INDEX idx1 ON MyTable (Col1) INCLUDE (Col2, Col3)
The INCLUDE clause is new to me. Why would you use it and what guidelines would you suggest in determining whether to create a covering index with or without the INCLUDE clause?
If the column is not in the
WHERE/JOIN/GROUP BY/ORDER BY, but only in the column list in theSELECTclause is where you useINCLUDE.The
INCLUDEclause adds the data at the lowest/leaf level, rather than in the index tree.This makes the index smaller because it’s not part of the tree
INCLUDE columnsare not key columns in the index, so they are not ordered.This means it isn’t really useful for predicates, sorting etc as I mentioned above. However, it may be useful if you have a residual lookup in a few rows from the key column(s)
Another MSDN article with a worked example