The SQL Server Index Strategy That Works 90% of the Time!

The SQL Server Index Strategy That Works 90% of the Time 👌👍

SQL Server Performance Series – Indexing Best Practices


Hi SQL SERVER Guys, 

Indexing is one of the most important aspects of SQL Server performance tuning.

A well-designed index can make a query run in milliseconds.

A poorly designed index can make the same query scan millions of rows.

The problem is that indexing strategies are often overcomplicated.

In reality, a relatively simple approach works in most real-world situations.

Today we look at an indexing strategy that works surprisingly well in about 90% of cases.


Clustered vs Nonclustered Indexes

Every SQL Server table should have a good clustered index.

The clustered index defines the physical order of the table data.

Without it, SQL Server creates a heap structure, which can lead to inefficient scans and fragmentation.

Typical choices for clustered indexes include:

  • primary keys
  • identity columns
  • monotonically increasing values

Nonclustered indexes are different.

They provide additional access paths to the data without changing the physical storage of the table.

Most performance improvements come from well-designed nonclustered indexes.


The Power of Covering Indexes

One of the most powerful indexing techniques is the covering index.

A covering index contains all the columns required by a query.

This allows SQL Server to retrieve the results directly from the index without accessing the base table.

For example:


SELECT OrderDate, TotalAmount
FROM Orders
WHERE CustomerID = 100

An effective index could look like this:


CREATE INDEX IX_Orders_CustomerID
ON Orders(CustomerID)
INCLUDE (OrderDate, TotalAmount)

This is fundamental!

Now, SQL Server can answer the query using only the index. 

This eliminates expensive key lookups.

More, SQL Server will not need to read data directly from the table: this is very good if your table is accessed by another query for example...



Included Columns

Included columns are a powerful feature of SQL Server indexes.

They allow you to add non-key columns to the index without affecting the index structure.

This has two major advantages:

  • smaller index keys
  • better query coverage

Instead of adding many columns to the index key, you can keep the key small and include the remaining columns.

This approach often improves both performance and maintainability.


When NOT to Create Indexes

More indexes do not always mean better performance.

Each index adds overhead to:

  • INSERT operations
  • UPDATE operations
  • DELETE operations

This is because SQL Server must maintain the index structure whenever the data changes.

Common indexing mistakes include:

  • too many overlapping indexes
  • indexes on very small tables
  • indexes that are never used

Indexes are powerful, but they should always be created with a clear purpose.


A Simple Index Strategy

In most real-world systems, the following strategy works extremely well:

  1. Create a good clustered index for every large table.
  2. Add nonclustered indexes for the most common query filters.
  3. Use covering indexes to avoid key lookups.
  4. Keep index keys small.
  5. Use included columns for additional query coverage.

This simple approach solves the majority of SQL Server performance issues.


The Real Lesson

Indexing is not about creating as many indexes as possible.

It is about creating the right indexes for the queries that matter.

Understanding how SQL Server uses indexes can dramatically improve query performance.

In many cases, a single well-designed index can reduce execution time by orders of magnitude.


Final Takeaways

  1. Always use a proper clustered index.
  2. Create nonclustered indexes for frequent filters.
  3. Use covering indexes when possible.
  4. Leverage included columns to reduce key size.
  5. Avoid unnecessary or overlapping indexes.

And remember…

No SQL Server was harmed while creating these indexes 😉

See you in the next SQL Server performance deep dive!


PS. If you missed my last post just click here: 

Why Your SQL Server Query Is Fast in SSMS but Slow in Production

Comments

I Post più popolari

Speaking to Sql Server, sniffing the TDS protocol

SQL Server, find text in a Trigger, Stored Procedures, View and Function. Two ways and what ways is better

SQL Server, Avoid that damn Table Spool!