Challenge - 5 Problems
Transaction Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output after running this transaction block?
Consider the following SQL commands executed in order:
What is the balance of the account with id = 1 after these commands?
BEGIN TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 100);
UPDATE accounts SET balance = balance + 50 WHERE id = 1;
ROLLBACK;
What is the balance of the account with id = 1 after these commands?
SQL
BEGIN TRANSACTION; INSERT INTO accounts (id, balance) VALUES (1, 100); UPDATE accounts SET balance = balance + 50 WHERE id = 1; ROLLBACK;
Attempts:
2 left
💡 Hint
ROLLBACK undoes all changes made in the transaction.
✗ Incorrect
The ROLLBACK command cancels all changes made since BEGIN TRANSACTION, so the insert and update are undone. Therefore, no row with id = 1 exists after rollback.
📝 Syntax
intermediate1:30remaining
Which option correctly starts a transaction in standard SQL?
Choose the correct syntax to begin a transaction in standard SQL.
Attempts:
2 left
💡 Hint
Standard SQL uses a specific phrase to start transactions.
✗ Incorrect
The standard SQL command to start a transaction is START TRANSACTION; other options are either vendor-specific or invalid.
🧠 Conceptual
advanced2:00remaining
What happens if you execute multiple BEGIN TRANSACTION statements without COMMIT or ROLLBACK?
In a database session, what is the effect of running multiple BEGIN TRANSACTION commands consecutively without committing or rolling back the previous transaction?
Attempts:
2 left
💡 Hint
Most databases do not support nested transactions by default.
✗ Incorrect
Standard SQL and many databases do not allow starting a new transaction before ending the previous one, so the second BEGIN TRANSACTION causes an error.
❓ optimization
advanced2:00remaining
How to optimize transaction usage for multiple related updates?
You need to update multiple related tables in a database. Which approach optimizes performance and data integrity?
Attempts:
2 left
💡 Hint
Grouping related changes in one transaction helps consistency.
✗ Incorrect
Using a single transaction for related updates ensures all changes succeed or fail together, improving integrity and often performance.
🔧 Debug
expert2:30remaining
Why does this transaction block cause an error?
Examine the following SQL code:
Why does this code cause an error?
BEGIN TRANSACTION;
INSERT INTO orders (id, amount) VALUES (1, 100);
BEGIN TRANSACTION;
UPDATE orders SET amount = 150 WHERE id = 1;
COMMIT;
Why does this code cause an error?
SQL
BEGIN TRANSACTION; INSERT INTO orders (id, amount) VALUES (1, 100); BEGIN TRANSACTION; UPDATE orders SET amount = 150 WHERE id = 1; COMMIT;
Attempts:
2 left
💡 Hint
Check if nested transactions are supported.
✗ Incorrect
Most databases do not support nested transactions by default, so starting a second BEGIN TRANSACTION before committing or rolling back the first causes an error.