Two examples are:
- Columns that will show up in a queries where clause (where Name = “xtz”)
- Columns that you are going to order (sort) on in queries
Is this correct and are there other important use cases?
Can SQL Server recommend fields to index based on usage patterns ?
You will know if your performance is not good enough.
The things you mention are parts of the solution already. In addition to those two, I would also add:
That helps tremedously when doing JOINs and it’s not done automatically by SQL Server (contrary to a common place urban myth floating around, SQL Server has never automatically put any indices on foreign keys).
Yes, as of SQL Server 2008, if you include the Actual Execution Plan in your query in SQL Server Management Studio, it can give you some hints as to what indices might help.
BUT CAREFUL: with this, you’re just tuning a single SQL query. You can tune that to the moon and back, but still have awful performance, since a single query often isn’t the whole story, and tuning one query to perform extremely well can negatively impact the rest of the system.
To REALLY know what to tune and how to tune it, you’ll need to capture actual real life usage data, using SQL Server profiler traces, over an extended period of time and at various times of the day of your system being in use, and examine those.
Read up on SQL Server Profiling:
Marc