Topic practice collection

Database Changes SQL practice questions

Practice safe SQL data changes, schema evolution, retry-safe upserts, transactions, rollback, views, and indexes in isolated databases.

Exercises
10
Difficulty
Beginner to Hard

What this collection tests

Skills and query patterns

INSERT, predicate-safe UPDATE and DELETE, CREATE and ALTER, upserts, transaction boundaries, rollback, views, and composite indexes

Curated exercises

Choose a problem

Work in the live editor where supported. Advanced guided labs state their engine boundary before you open the workspace.

  1. Problem 1Beginner

    Add a New Customer Account

    Insert account 5 as Summit Health with tier growth, status active, and a 15000 credit limit.

    • INSERT
    • Explicit column lists

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  2. Problem 2Easy

    Escalate Pending Orders Safely

    Change pending orders for account 1 to review.

    • UPDATE
    • Predicate safety

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  3. Problem 3Easy

    Remove Expired Cancelled Orders

    Delete cancelled orders placed before 2025-01-01.

    • DELETE
    • Predicate safety
    • Date filtering

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  4. Problem 4Hard

    Upsert a Retry-Safe Account Sync

    Upsert account 2 so Northstar Growth is enterprise, active, and has a 14000 credit limit.

    • UPSERT
    • Idempotency

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  5. Problem 5Easy

    Create an Account Notes Table

    Create account_notes with note_id, account_id, note_text, and created_at.

    • Table creation
    • Keys and constraints

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  6. Problem 6Medium

    Add and Backfill Account Risk

    Add risk_rating VARCHAR(10), then set it to high for credit limits at least 20000 and standard otherwise.

    • Schema migration
    • Data backfill
    • CASE expressions

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  7. Problem 7Easy

    Publish an Active-Account View

    Create active_account_summary exposing account_id, account_name, tier, and credit_limit for active accounts.

    • Views
    • Filtering

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  8. Problem 8Medium

    Commit a Coordinated Account Upgrade

    In one transaction, add 1000 to account 2's credit limit and insert order 505 for 1000 with pending status and date 2025-03-01.

    • Transactions
    • COMMIT
    • Atomicity

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  9. Problem 9Medium

    Roll Back a Rejected Account Closure

    Start a transaction, set account 3 to inactive, delete its pending orders, and then roll back the entire simulation.

    • Transactions
    • ROLLBACK
    • Atomicity

    SQLite + PostgreSQL live · 3 guided

    Open problem →
  10. Problem 10Medium

    Index the Account Order Lookup

    Create idx_orders_account_status on orders(account_id, status).

    • Composite indexes
    • Index design

    SQLite + PostgreSQL live · 3 guided

    Open problem →
01

Attempt

Write a query or design from the brief before opening any hints.

02

Validate

Run it against the included dataset and inspect the output.

03

Explain

Compare the verified answer and explain each choice aloud.

Learn before practicing Database Changes

Strengthen your understanding with these targeted learning topics: