Skip to main content
SQL Code Reorder Hard +35 XP

Transaction Block

Arrange a safe database transaction.

Click lines in the correct order

Available lines5 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: BEGIN TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE id = 1; IF @@ERROR <> 0 ROLLBACK; COMMIT;

Start the transaction, perform work, check for errors and rollback if needed, otherwise commit.

Hint: BEGIN before work, COMMIT or ROLLBACK after.

What this challenge tests

Code Reorder in SQL: transactions, acid.

Related challenges