A company uses Azure SQL Database for a customer management system. The Customers table has columns: CustomerID (int, primary key), FullName (varchar(100)), Email (varchar(200)), SignUpDate (date), LastLoginDate (date). Queries frequently filter on LastLoginDate to find customers who have not logged in for over a year for a promotional campaign. The table has 10 million rows. Which type of index should they create to optimize these queries?
A non-clustered index on LastLoginDate creates a separate B-tree structure ordered by that column, allowing SQL Server to perform an index seek directly for the date-range predicate. For a query such as WHERE LastLoginDate BETWEEN '2023-01-01' AND '2023-12-31', the engine navigates the index to the starting date and reads only the matching index entries, then uses bookmark lookups to fetch the full customer rows. This drastically reduces I/O compared to scanning every row in the table, making it the ideal choice for this filtering pattern.
Why this answer
A non-clustered index on LastLoginDate allows the query to quickly locate rows where LastLoginDate is older than one year without scanning the entire 10-million-row table. Azure SQL Database uses B-tree structures for non-clustered indexes, enabling efficient range scans and key lookups for the filtered rows. This directly supports the promotional campaign query pattern.
Exam trap
The trap here is that candidates often choose a clustered index on the primary key by default, failing to recognize that the query predicate (LastLoginDate) is not the clustering key, so the index cannot be used to efficiently filter the data.
Why the other options are wrong
A clustered index on CustomerID sorts the table by CustomerID, but the query filters on LastLoginDate. Without an index on LastLoginDate, the query must scan all 10 million rows, which is inefficient.
The query filters on LastLoginDate, not FullName. A non-clustered index on FullName would not help the query because it does not include the filter column, so the query would still require a full table scan.
A columnstore index is optimized for large-scale analytical queries (e.g., aggregations over many rows), not for point lookups or range scans on a single column like LastLoginDate. The query filters on a single date column, which is better served by a non-clustered index.