1Z0-062 · Question #379
Examine these statements: DESC emp INSERT INTO emp VALUES ( 101, 'John', 12000); 1 row created. SAVEPOINT after_insert; Savepoint created. UPDATE emp SET salary=16000 WHERE empno=101; 1 row updated…
The correct answer is B. The ROLLBACK backs out all DMLS until after_delete. If ROLLBACK TO SAVEPOINT after_update does not invalidate subsequent savepoints, then the final ROLLBACK TO SAVEPOINT after_delete successfully undoes all DMLs that occurred after the after_delete savepoint was initially created, resulting in the table state immediately…
Question
Examine these statements:
DESC emp INSERT INTO emp VALUES ( 101, 'John', 12000); 1 row created. SAVEPOINT after_insert; Savepoint created. UPDATE emp SET salary=16000 WHERE empno=101; 1 row updated. SAVEPOINT after_update; Savepoint created. DELETE FROM emp WHERE empno=101; 1 row deleted. SAVEPOINT after_delete; Savepoint created. ROLLBACK TO SAVEPOINT after_update; Rollback complete. INSERT INTO emp VALUES ( 102, 'Emma', 12000); ROLLBACK TO SAVEPOINT after_delete; Which is the result and effect of this ROLLBACK?
Exhibit
Options
- AThe ROLLBACK backs out all DMLS before after_delete.
- BThe ROLLBACK backs out all DMLS until after_delete.
- CThe ROLLBACK throws an error.
- DThe ROLLBACK executes successfully but does not back out any DMLS.
How the community answered
(28 responses)- A11% (3)
- B71% (20)
- C4% (1)
- D14% (4)
Why each option
If `ROLLBACK TO SAVEPOINT after_update` does not invalidate subsequent savepoints, then the final `ROLLBACK TO SAVEPOINT after_delete` successfully undoes all DMLs that occurred after the `after_delete` savepoint was initially created, resulting in the table state immediately following the `DELETE` command.
The `ROLLBACK TO SAVEPOINT` command specifically undoes DML operations that occurred *after* the specified savepoint, not before it, while preserving DMLs up to the savepoint.
Assuming the initial `ROLLBACK TO SAVEPOINT after_update` does not invalidate subsequent savepoints, the final `ROLLBACK TO SAVEPOINT after_delete` command would successfully execute. It effectively undoes the `INSERT INTO emp VALUES (102, 'Emma', 12000)` and restores the table to the state it was in immediately after the original `DELETE FROM emp WHERE empno=101` and `SAVEPOINT after_delete` commands, which means the `emp` table would be empty.
Standard Oracle behavior dictates that `ROLLBACK TO SAVEPOINT after_update` would discard the `after_delete` savepoint, causing the subsequent `ROLLBACK TO SAVEPOINT after_delete` to fail with an error; however, the provided correct answer implies this standard behavior is not followed in this context.
If the `ROLLBACK TO SAVEPOINT after_delete` command successfully executes, it would indeed back out the `INSERT 102` DML operation and potentially other changes, therefore it would not result in no DMLs being backed out.
Concept tested: Oracle Transaction Control - SAVEPOINT and ROLLBACK TO SAVEPOINT
Source: https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/ROLLBACK.html#GUID-E500F928-85F0-4C3D-B27D-5A817290A92C
Topics
Community Discussion
No community discussion yet for this question.
