Hard Transactions Premium

SQL interview question: SAVEPOINT and ROLLBACK TO

The Reversible Experiment

Finance (department_id 5) gets a confirmed $1,000 raise per person. While you're in there, an analyst wants to trial-run doubling every salary - but that experiment must NOT survive.

Write one transaction that: applies the Finance raise, opens a SAVEPOINT named experiment, doubles every salary, rolls back to the savepoint, and COMMITs. Only the Finance raise should remain.

Note: Multiple statements allowed. Runs on a scratch copy and is discarded afterwards.

Tables

employees 37 rows
  • id integer PK
  • first_name text
  • last_name text
  • email text
  • department_id integer → departments
  • salary integer
  • hire_date text
  • manager_id integer → employees
  • title text
idfirst_namelast_nameemaildepartment_idsalaryhire_datemanager_idtitle
1AliceChen[email protected]12500002015-01-15NULLCEO
2RobertMartinez[email protected]21800002016-03-20NULLCEO
3SarahJohnson[email protected]11500002017-06-101VP Engineering

Keep going