0
0
MySQLquery~20 mins

Savepoints in MySQL - 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 after rolling back to a savepoint
Consider the following MySQL transaction:

START TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 1000);
SAVEPOINT sp1;
UPDATE accounts SET balance = balance - 200 WHERE id = 1;
ROLLBACK TO SAVEPOINT sp1;
SELECT balance FROM accounts WHERE id = 1;

What will be the output of the SELECT query?
MySQL
START TRANSACTION;
INSERT INTO accounts (id, balance) VALUES (1, 1000);
SAVEPOINT sp1;
UPDATE accounts SET balance = balance - 200 WHERE id = 1;
ROLLBACK TO SAVEPOINT sp1;
SELECT balance FROM accounts WHERE id = 1;
A[{"balance": 1000}]
B[{"balance": 800}]
CEmpty result set
DSyntax error
Attempts:
2 left
💡 Hint
Rolling back to a savepoint undoes changes after that savepoint.
🧠 Conceptual
intermediate
1:30remaining
Purpose of savepoints in transactions
What is the main purpose of using savepoints within a database transaction?
ATo permanently save data to the database immediately
BTo speed up query execution by caching results
CTo allow partial rollback of a transaction without aborting the entire transaction
DTo create a backup copy of the database
Attempts:
2 left
💡 Hint
Think about what rollback to a savepoint does.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in savepoint usage
Which of the following MySQL statements contains a syntax error related to savepoints?
AROLLBACK SAVEPOINT sp1;
BROLLBACK TO SAVEPOINT sp1;
CRELEASE SAVEPOINT sp1;
DSAVEPOINT sp1;
Attempts:
2 left
💡 Hint
Check the correct syntax for rolling back to a savepoint.
🔧 Debug
advanced
2:00remaining
Why does releasing a savepoint cause an error?
Given the following sequence:

START TRANSACTION;
SAVEPOINT sp1;
RELEASE SAVEPOINT sp1;
ROLLBACK TO SAVEPOINT sp1;

Why does the last statement cause an error?
MySQL
START TRANSACTION;
SAVEPOINT sp1;
RELEASE SAVEPOINT sp1;
ROLLBACK TO SAVEPOINT sp1;
ABecause rollback to savepoint is not allowed inside transactions
BBecause the savepoint 'sp1' no longer exists after being released
CBecause savepoints cannot be released once created
DBecause the transaction was already committed
Attempts:
2 left
💡 Hint
What does releasing a savepoint do?
optimization
expert
2:30remaining
Optimizing transaction control with savepoints
You have a long transaction with multiple steps. You want to undo only the last step if it fails, without aborting the entire transaction. Which approach is best?
AAvoid using transactions and rely on auto-commit
BCommit the transaction before the last step and start a new transaction
CUse multiple separate transactions for each step
DUse a savepoint before the last step and rollback to it if the step fails
Attempts:
2 left
💡 Hint
Think about partial rollback within a transaction.