SQL Topic collection

Database Changes SQL Topic exercises

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 an exercise

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

  1. Exercise 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 exercise
  2. Exercise 2Easy

    Escalate Pending Orders Safely

    Change pending orders for account 1 to review.

    • UPDATE
    • Predicate safety

    SQLite + PostgreSQL live · 3 guided

    Open exercise
  3. Exercise 3Easy

    Remove Expired Cancelled Orders

    Delete cancelled orders placed before 2025-01-01.

    • DELETE
    • Predicate safety
    • Date filtering

    SQLite + PostgreSQL live · 3 guided

    Open exercise
  4. Exercise 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 exercise
  5. Exercise 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 exercise
  6. Exercise 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 exercise
  7. Exercise 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 exercise
  8. Exercise 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 exercise
  9. Exercise 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 exercise
  10. Exercise 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 exercise
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:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.