2. • A transaction is a logical, atomic unit of work
that contains one or more SQL statements.
• A transaction must be EITHER
– Saved with COMMIT statement
– Rollback together with ROLLBACK statement
• Comply with ACID properties
3. ACID Properties
• Atomicity
– All tasks of a transaction are performed or none of
them are.
• Consistency
– The transaction takes the database from one
consistent state to another consistent state.
• Isolation
– The effect of a transaction is not visible to other
transactions until the transaction is committed.
4. ACID Properties
• Durability
– Changes made by committed transactions are
permanent.
– After a transaction completes, the database
ensures through its recovery mechanisms that
changes from the transaction are not lost.
5. Transactions
• Beginning a Transaction
– A transaction begins when the first executable SQL
statement is encountered
• End a Transaction
– A COMMIT or ROLLBACK statement issued by user
without a SAVEPOINT clause.
– DDL command runs by user.
– A user exits normally.
7. Transaction Control
• Management of changes made by DML statements and
the grouping of DML statements into transactions.
• Data changes made by a transaction are temporary
until the transaction is committed or rolled back.
• Transaction Control involves
– COMMIT
– ROLLBACK
– SAVEPOINT
8. Transaction Controls
• Active Transactions
– An active transaction has started but not yet
committed or rolled back.
• Before the transaction ends, the state of the data
is as follows:
– Oracle Database has generated undo data
information in the system global area (SGA).
– Changes have been made to the database buffers of
the SGA.
– The rows affected by the data change are locked.
9. Transaction Control
• COMMIT
– A commit ends the current transaction and makes
permanent all changes performed in the transaction.
COMMIT [WORK] [COMMENT text];
– When a transaction commits, the following actions
occur:
• Oracle Database releases locks held on rows and tables.
• Oracle Database deletes savepoints.
• Oracle Database marks the transaction complete.
10. Transaction Control
• ROLLBACK
– Undoing any changes that have occurred in the
current UNCOMMITTED transaction.
– All data changes discarded.
ROLLBACK [TO SAVEPOINT] savepoint_name;
11. Transaction Control
• When ROLLBACK
– All changes made by the current transaction are
undone.
– All locks released.
– All savepoints released.
– Transaction ends
12. Transaction Control
• When ROLLBACK TO SAVEPOINT
– When SAVEPOINT occurs following thing occurs:
• Oracle Database rolls back only the statements run
after the savepoint.
• Oracle Database preserves the savepoint specified in
the ROLLBACK TO SAVEPOINT statement, but all
subsequent savepoints are lost.
• Oracle Database releases all table and row locks
– The transaction remains active and can be
continued.
13. Transaction Control
• SAVEPOINT
– The SAVEPOINT statement identifies a point in a
transaction to which you can later roll back.
– To rollback transaction partially , we create
savepoints.
SAVEPOINT savepoint_name
14. Transaction Control
T0 COMMIT
T1 SET TRANSACTION NAME ‘my_trans';
T2 UPDATE.....
T3 SAVEPOINT svFirst
T4 UPDATE.....
T5 SAVEPOINT svSecond
T6 ROLLBACK TO svFirst
T7 UPDATE....
T8 ROLLBACK