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

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

Exercise brief

Understand the request

Compliance operations The team must prove that multiple tentative changes can be abandoned together when an approval is withdrawn.

A closure simulation changes an account and its pending orders, but compliance rejects the request before anything becomes durable.

Return

  • Execute both tentative changes and leave the seeded database unchanged.

Constraints

  • Use an explicit transaction boundary.
  • Run UPDATE before DELETE.
  • Finish with ROLLBACK, not COMMIT.

Data you will use

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

accounts

  • account_idINTEGER
  • statusVARCHAR(20)

orders

  • order_idINTEGER
  • account_idINTEGER
  • statusVARCHAR(20)

Hints, when you need them

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

Hint 1

ROLLBACK ends the transaction and discards every uncommitted change in that unit of work.

Hint 2

The required sequence is BEGIN, UPDATE, DELETE, ROLLBACK.

Hint 3

BEGIN; UPDATE accounts ...; DELETE FROM orders ...; ROLLBACK;

Verified SQL answer

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

Reveal solution and explanation
BEGIN;
UPDATE accounts
SET status = 'inactive'
WHERE account_id = 3;
DELETE FROM orders
WHERE account_id = 3 AND status = 'pending';
ROLLBACK;

Why this works

A rollback exercise makes atomicity observable from the unchanged final state and distinguishes transaction control from merely issuing multiple statements.

Success check

Account 3 remains trial and every original order remains after the rollback completes.

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.