Database Changes SQL Topic exerciseMediumVerified answerSQLite + PostgreSQL live · 3 guided

Index the Account Order Lookup

Create idx_orders_account_status on orders(account_id, status).

  • Composite indexes
  • Index design

Exercise brief

Understand the request

Database reliability The common support lookup filters orders by account_id and then status.

Order support repeatedly searches by account and status as the order table grows.

Return

  • Create the named composite index with columns in lookup order.

Constraints

  • Use the exact index name.
  • Place account_id before status.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

orders

  • account_idINTEGER
  • statusVARCHAR(20)

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

A composite index can support filters that begin with its leading column.

Hint 2

Use CREATE INDEX with the exact name and list account_id before status.

Hint 3

CREATE INDEX idx_orders_account_status ON orders (account_id, status);

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
CREATE INDEX idx_orders_account_status
ON orders (account_id, status);

Why this works

The index order matches the stated access pattern and establishes a concrete performance object that can be inspected in the catalog.

Success check

The database catalog contains idx_orders_account_status on the orders table.

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.