🙏 We need your help! SQLtest.online has no ads and lives only on donations. Even a small amount helps. Donate now →
SQL code copied to buffer
Task 26:

Index for the Customer Order History

SQL Server 2022
The "My orders" page runs this query for every customer:
SELECT OrderDate, TotalDue FROM SalesOrderHeader WHERE CustomerID = @id ORDER BY OrderDate;
The task runs on a small copy of SalesOrderHeader; its primary key SalesOrderID is the clustered index.
Create one nonclustered index that finds the customer's orders already sorted by date and also holds TotalDue, so that the query never reads the table itself. TotalDue is not used for searching or sorting, so it must not be a key column. The index name is up to you.
Expected result Columns: 3 · Rows: 2
index_type key_columns included_columns

Write your query below and click "Check it!". Tables are described in the right pane.

Tutorial

By checking a query, you agree that it is stored without your account details and may be included in anonymized datasets, including for AI training. Learn more

The query result will appear here. Ctrl+Enter - Run query