Oracle Database SQL (1Z0-071) free question 2 / 10 · Domain 10: Managing Tables using DML statements
Three rows, A, B, and C, of the employees table were processed in the following order. After the COMMIT, which rows have their update saved? UPDATE employees SET salary = salary + 100 WHERE last_name = 'A'; SAVEPOINT s1; UPDATE employees SET salary = salary + 100 WHERE last_name = 'B'; SAVEPOINT s2; UPDATE employees SET salary = salary + 100 WHERE last_name = 'C'; ROLLBACK TO SAVEPOINT s1; COMMIT;
- The three rows A, B, and C
- The one row A is saved
- A and B, the first two rows
- No rows are saved
Show the answer and explanation
Answer: B
Why this is correct
"ROLLBACK" in the SQL Language Reference says that a ROLLBACK with a TO SAVEPOINT clause rolls back just the portion of the transaction after the savepoint, and that it does not end the transaction. The updates to B and C after s1 are undone, and the update to A before s1 is saved by the COMMIT.
Why the other options are wrong
"A and B, the first two rows" … That is the result if ROLLBACK TO SAVEPOINT s2 had been run. A rollback to a savepoint undoes the changes after it, so going back to s1 undoes the update to B as well.
"The three rows A, B, and C" … That is the result if ROLLBACK TO SAVEPOINT had not been run. Updates after s1 are undone, so the updates to B and C do not remain.
"No rows are saved" … A rollback to a savepoint does not undo the whole transaction. The update to A before s1 is not undone and is committed by the COMMIT.
Key takeaway
ROLLBACK TO SAVEPOINT undoes only the changes after the named savepoint. Changes before it can still be committed by a later COMMIT.