Courseiva

How to Design a Covering Index for Filter and Sort Queries in Azure SQL Database

A library management system uses Azure SQL Database. The Books table has 500,000 rows with columns: BookID (primary key, clustered), Title, Author, ISBN, PublishedYear, CopiesAvailable. Queries frequently filter by Author and then sort results by PublishedYear in descending order. Which indexing strategy will most improve query performance?

Quick Answer

The correct choice is to create a nonclustered index on (Author, PublishedYear DESC) INCLUDE (CopiesAvailable, Title, ISBN). This strategy works because it builds a covering index for filter and sort queries, allowing SQL Server to seek directly on the Author column and then scan the PublishedYear values in descending order without needing a separate sort operation. By including the remaining columns as non-key entries, the index covers all data requested, eliminating expensive key lookups to the clustered index. On the DP-900 exam, this scenario tests your understanding of how index key order and included columns directly impact query performance—a common trap is choosing an index that only filters but forces a sort afterward. Remember the memory tip: "Key it to filter, order it to sort, include the rest to cover."

⚠ Common exam trap

Test-takers frequently choose Option A because they think INCLUDING PublishedYear is sufficient for sorting, but they miss that the index key order must match the ORDER BY clause to avoid an explicit sort operation.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Create a nonclustered index on (Author, PublishedYear DESC) INCLUDE (CopiesAvailable, Title, ISBN).

It creates a covering index that matches the exact query pattern: filtering by Author and sorting by PublishedYear in descending order. By defining (Author, PublishedYear DESC) as the index key, SQL Server can perform an index seek on Author and an ordered scan on PublishedYear without a separate sort operation. Including the remaining columns (CopiesAvailable, Title, ISBN) as non-key columns makes the index covering, eliminating the need for key lookups to the clustered index.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Create a nonclustered index on (Author) INCLUDE (PublishedYear, CopiesAvailable, Title).

    Why it's wrong here

    This index covers the filter on Author but does not specify the sort order on PublishedYear. The database may still need to sort the results, which is less efficient.

  • Create a nonclustered index on (PublishedYear) INCLUDE (Author).

    Why it's wrong here

    This index is ordered by PublishedYear, but the primary filter is on Author. The database would need to scan or use lookups for each Author, which is inefficient.

  • Create a nonclustered index on (Author, PublishedYear DESC) INCLUDE (CopiesAvailable, Title, ISBN).

    Why this is correct

    This index is sorted by Author first and then PublishedYear descending, perfectly supporting both the filter and the sort. Included columns make it covering.

  • Create a nonclustered columnstore index on (Author, PublishedYear, CopiesAvailable, Title, ISBN).

    Why it's wrong here

    Columnstore indexes are designed for large scan-heavy analytical queries, not for point lookups and sorted retrieval of few rows. This would not improve performance for this OLTP-style query.

About these practice questions

This DP-900 question is part of Courseiva's 820-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

4 more ways this is tested on DP-900

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A library management system uses Azure SQL Database. The Books table has 500,000 rows with columns: BookID (primary key, clustered), Title, Author, ISBN, PublishedYear, CopiesAvailable. Queries frequently filter by Author and then sort results by PublishedYear in descending order. The queries also return the Title and CopiesAvailable columns. Which indexing strategy will most improve query performance for these operations?

medium
  • A.Create a nonclustered index on (Author, PublishedYear DESC) and include (Title, CopiesAvailable)
  • B.Create a nonclustered index on Author only
  • C.Create a nonclustered index on PublishedYear DESC
  • D.Keep only the existing clustered index on BookID

Why A: It creates a covering nonclustered index on (Author, PublishedYear DESC) that directly supports the filter (Author) and sort (PublishedYear DESC) operations. Including Title and CopiesAvailable as non-key columns makes the index covering, meaning all required columns are in the index leaf level, so SQL Server can satisfy the query entirely from the index without key lookups to the clustered index. This minimizes I/O and improves query performance.

Variation 2. A company uses Azure SQL Database for an HR system. The Employees table has a clustered index on EmployeeID. Queries frequently filter on DepartmentID and LastName and also retrieve the Salary column. The table contains over a million rows. Which index strategy will most improve query performance for these filters?

medium
  • A.A: Create a nonclustered index on (DepartmentID, LastName) INCLUDE (Salary)
  • B.B: Create a nonclustered index on LastName only
  • C.C: Create a nonclustered index on DepartmentID and another nonclustered index on LastName
  • D.D: Change the clustered index to (DepartmentID, LastName)

Why A: It creates a covering nonclustered index on the filter columns (DepartmentID, LastName) and includes the Salary column as an included column. This allows the query to be fully satisfied by scanning only the nonclustered index pages, avoiding key lookups to the clustered index. The order of columns in the index key matches the query filter pattern, maximizing seek efficiency.

Variation 3. A company has a table named 'Sales' in Azure SQL Database with columns: SaleID (int, primary key), ProductID (int), SaleDate (datetime), Quantity (int), UnitPrice (decimal), TotalAmount (computed column). Queries frequently run to retrieve the total Quantity and UnitPrice for a specific ProductID over a date range. The query filters on ProductID and SaleDate and selects only Quantity and UnitPrice. Which index would most improve query performance?

medium
  • A.Nonclustered index on (ProductID, SaleDate) INCLUDE (Quantity, UnitPrice)
  • B.Nonclustered index on (SaleDate) INCLUDE (Quantity, UnitPrice)
  • C.Clustered index on (ProductID, SaleDate)
  • D.Nonclustered index on (ProductID) INCLUDE (Quantity, UnitPrice)

Why A: It creates a covering nonclustered index that supports both the WHERE clause (ProductID, SaleDate) and the SELECT clause (Quantity, UnitPrice) without needing to access the base table. The index key order matches the query filter, and the included columns avoid key lookups, minimizing I/O for the frequent aggregation queries.

Variation 4. A company uses Azure SQL Database for its e-commerce platform. During a traffic spike, queries against the Orders table become slow. The table has 10 million rows and is clustered on OrderId. The most common query filters by CustomerId and OrderDate range. Which index change would most improve performance?

hard
  • A.Create a clustered index on CustomerId
  • B.Partition the table by OrderId
  • C.Create a nonclustered index on (CustomerId, OrderDate)
  • D.Create a nonclustered index on (OrderDate, CustomerId)

Why C: The most common query filters by CustomerId and OrderDate, so a nonclustered index on (CustomerId, OrderDate) provides a covering index that allows the database engine to quickly locate rows without scanning the entire clustered index. This index order supports equality on CustomerId and range scans on OrderDate, which is optimal for the query pattern. In Azure SQL Database, this reduces I/O and improves response time during traffic spikes.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DP-900 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DP-900 exam.