0
0
SQLquery~20 mins

Savepoints within transactions in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Savepoint Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of nested savepoints in a transaction
Consider the following SQL transaction with savepoints:

BEGIN TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 100);
SAVEPOINT sp1;
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
SAVEPOINT sp2;
UPDATE accounts SET balance = balance + 30 WHERE id = 1;
ROLLBACK TO SAVEPOINT sp1;
COMMIT;

What is the final balance of the account with id = 1 after this transaction?
A100
B80
C130
D50
Attempts:
2 left
💡 Hint
Rolling back to savepoint sp1 undoes changes after sp1 but keeps changes before it.
🧠 Conceptual
intermediate
1:30remaining
Purpose of savepoints in transactions
What is the main purpose of using savepoints within a database transaction?
ATo create a backup copy of the database
BTo permanently save data changes to the database immediately
CTo speed up query execution by caching results
DTo allow partial rollback of a transaction without aborting the entire transaction
Attempts:
2 left
💡 Hint
Think about what happens when you want to undo some changes but keep others in the same transaction.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in savepoint usage
Which of the following SQL statements will cause a syntax error when using savepoints inside a transaction?
ASAVEPOINT;
BSAVEPOINT sp1;
CRELEASE SAVEPOINT sp1;
DROLLBACK TO sp1;
Attempts:
2 left
💡 Hint
Check if the savepoint statement includes all required parts.
🔧 Debug
advanced
2:00remaining
Why does this rollback not undo changes?
Given this transaction:

BEGIN TRANSACTION;
INSERT INTO orders (id, amount) VALUES (1, 200);
SAVEPOINT sp1;
UPDATE orders SET amount = 300 WHERE id = 1;
ROLLBACK TO SAVEPOINT sp2;
COMMIT;

Why does the rollback not undo the update?
ABecause rollback to savepoint requires a semicolon after the savepoint name
BBecause savepoint sp2 was never created, so rollback to it fails silently
CBecause rollback to savepoint only works after commit
DBecause rollback to savepoint undoes only inserts, not updates
Attempts:
2 left
💡 Hint
Check if the savepoint name used in rollback exists.
optimization
expert
2:30remaining
Optimizing transaction with multiple savepoints
You have a long transaction with multiple savepoints to handle errors in different steps. Which approach optimizes performance and resource usage best?
AUse savepoints but never release them until the transaction ends
BCreate savepoints before every single statement to maximize rollback options
CUse savepoints only before steps that are likely to fail, and release savepoints after they are no longer needed
DAvoid using savepoints and instead commit after each step to isolate errors
Attempts:
2 left
💡 Hint
Think about balancing rollback flexibility with overhead of managing savepoints.