SQL interview question: Create an Index
Speed Up Customer Lookups
The dashboard's most frequent query is "orders for customer X", and it's doing a full table scan every time.
Create an index named exactly idx_orders_customer on the customer_id column of orders.
Note: Your index is verified automatically (including which column it covers) and rolled back afterwards.
This challenge changes data. Your statement runs on a private copy of the database, then we check the resulting table.
Tables
orders 15 rows
- order_id integer PK
- customer_id integer → customers
- order_date text
- total_amount real
- status text
| order_id | customer_id | order_date | total_amount | status |
|---|---|---|---|---|
| 1 | 101 | 2024-01-20 | 249.99 | delivered |
| 2 | 101 | 2024-03-15 | 1999.99 | delivered |
| 4 | 101 | 2024-09-05 | 79.99 | delivered |