Question 1
In Oracle Database, a session runs the following, in order, with no other statements between them and no error from any of the INSERTs. AUDIT was empty to start and no other session is involved: ```sql INSERT INTO audit (id) VALUES (1); SAVEPOINT sp; INSERT INTO audit (id) VALUES (2); SAVEPOINT sp; INSERT INTO audit (id) VALUES (3); ROLLBACK TO sp; COMMIT; ``` Note that the savepoint name `sp` is used twice. After the COMMIT completes, which rows are persisted in AUDIT?
A. Only row 1 persists; rows 2 and 3 are rolled back.
This is the 'first savepoint wins' misconception: it assumes ROLLBACK TO sp returns to the original SAVEPOINT sp declared before row 2. But a reused savepoint name erases the earlier savepoint, so only the second definition (after row 2) survives; the rollback cannot reach a position that no longer exists.
B. The second `SAVEPOINT sp` fails with an error because savepoint names must be unique within a transaction.
This invents a prohibition that does not exist. Oracle explicitly permits reusing a savepoint identifier and defines the behaviour — the earlier savepoint is silently erased and the name is redefined — rather than raising an error, so all three INSERTs and the reused SAVEPOINT execute cleanly.
C. Rows 1 and 2 persist; only row 3 is rolled back.Correct answer
Reusing an existing savepoint identifier erases the earlier savepoint and relocates the name to the new position (immediately after row 2's insert). ROLLBACK TO sp therefore rewinds only to that later point, discarding row 3, while rows 1 and 2 remain in the still-open transaction and are made permanent by the COMMIT. The reference states that creating a second savepoint with the same identifier as an earlier one erases the earlier savepoint.
D. All three rows persist, because the later COMMIT re-applies the work that ROLLBACK TO sp had set aside.
This misreads ROLLBACK TO SAVEPOINT as a reversible marker that a COMMIT can undo. Rolling back to a savepoint permanently discards the changes made after it (row 3 here); a subsequent COMMIT persists only the work that still survives in the transaction, it cannot restore rolled-back changes.
Explanation
Reusing a savepoint identifier neither raises an error nor creates two distinct savepoints: the later declaration erases the earlier one, so the name refers only to its most recent position. A rollback to that name therefore discards just the work performed after the second declaration, leaving everything before it intact within the still-open transaction, and the following COMMIT makes that surviving work durable. The overlooked rule is that the original savepoint no longer exists once the name is reused — assuming it does, or assuming a duplicate name is illegal, flips the answer.