Presented By:
Deepshikha Haritwal
(MCA/25001/18)
Roopak Bhama
(MCA/25003/18)
Contents
• Introduction to transactions
• Transaction Control
• Properties of transactions
• States of transactions
What is a Transaction?
• A transaction is a basic unit of program
execution which possibly access and update
various data items in a database.
• Collection of operations that form a single
logical unit of work are called transactions.
• A transaction is delimited by statements of the
form begin transaction and end transaction.
• The transaction consists of all operations
executed between the begin transaction and end
transaction.
Example of Transaction
• A withdrawal transaction in an ATM could
consist of following steps:
▫ Verify account details
▫ Accept withdrawal request
▫ Check balance
▫ Update balance
▫ Dispense money
Transaction control
• The following commands are used to control
transactions.
▫ COMMIT − to save the changes.
▫ ROLLBACK − to roll back the changes.
▫ SAVEPOINT − creates points within the groups of
transactions in which to ROLLBACK.
▫ SET TRANSACTION − Places a name on a
transaction.
Commit command
• The commit command is the transactional
command used to save changes invoked by a
transaction to the database.
• The syntax for the commit command is as
follows:
▫ COMMIT;
• Example :
▫ sql?>DELETE FROM CUSTOMERS WHERE AGE
= 25;
▫ sql> COMMIT;
Rollback command
• The rollback command is the transactional
command used to undo transactions that have
not already been saved to the database.
• The syntax for a rollback command is −
▫ ROLLBACK;
• Example :
▫ SQL> DELETE FROM CUSTOMERS WHERE
AGE = 25;
▫ SQL> ROLLBACK;
Savepoint command
• A savepoint is a point in a transaction when you
can roll the transaction back to a certain point
without rolling back the entire transaction.
• The syntax for a savepoint command is:
▫ SAVEPOINT SAVEPOINT_NAME;
Set transaction command
• The set transaction command can be used to
initiate a database transaction.
• For example we can specify a transaction to be
read only or read write.
• The syntax for a set transaction command is:
▫ SET TRANSACTION [ READ WRITE | READ
ONLY ];
Properties of Transactions
• In order to maintain consistency in a database,
before and after transaction, certain properties
are followed.
• These are called ACID properties.
▫ A: Atomicity
▫ C: Consistency
▫ I: Isolation
▫ D: Durability
Atomicity
• It means that the entire transaction takes place
at once or doesn’t happen at all.
• There is no midway i.e. transactions do not
occur partially.
• It involves following two operations.
▫ Abort: If a transaction aborts, changes made to
database are not visible.
▫ Commit: If a transaction commits, changes made
are visible.
• Atomicity is also known as the ‘All or nothing
rule’.
Consistency
• This means that integrity constraints must be
maintained so that the database is consistent
before and after the transaction.
• It refers to correctness of a database.
Isolation
• This property ensures that multiple transactions
can occur concurrently without leading to
inconsistency of database state.
• Transactions occur independently without
interference.
• Changes occurring in a particular transaction
will not be visible to any other transaction until
that particular change in that transaction is
written to memory or has been committed.
Durability
• This property ensures that once the transaction
has completed execution, the updates and
modifications to the database are stored in and
written to disk.
• These updates now become permanent and are
stored in a non-volatile memory.
• The effects of the transaction, thus, are never
lost.
Transaction States
• While the transaction executes in a database it
could be in one of the following states:
▫ Active : In this state, the transaction is being
executed. This is the initial state of every
transaction.
▫ Partially committed: When a transaction
executes its final operation, it is said to be in a
partially committed state.
▫ Failed : A transaction is said to be in a failed state
if any of the checks made by the database recovery
system fails. A failed transaction can no longer
proceed further.
▫ Aborted: If any of the checks fails and the
transaction has reached a failed state, then the
recovery manager rolls back all its write operations
on the database to bring the database back to its
original state where it was prior to the execution of
the transaction. Transactions in this state are
called aborted.
▫ Committed: If a transaction executes all its
operations successfully, it is said to be committed.
All its effects are now permanently established on
the database system
Demonstrating transaction states
• Consider a user making a booking for a flight
over a web.
• While the user is selecting the time for departure
and the seat available, the transaction is said to
be in active state.
• When the user is making the payment for the
tickets, the transaction is said to be partially
commited.
• While making the payment if the system crashes
or network connection goes off, the transaction
may be aborted.
• Otherwise, if successful payment is made the
transaction is said to be committed.
Transaction Processing its properties & States

Transaction Processing its properties & States

  • 1.
  • 2.
    Contents • Introduction totransactions • Transaction Control • Properties of transactions • States of transactions
  • 3.
    What is aTransaction? • A transaction is a basic unit of program execution which possibly access and update various data items in a database. • Collection of operations that form a single logical unit of work are called transactions.
  • 4.
    • A transactionis delimited by statements of the form begin transaction and end transaction. • The transaction consists of all operations executed between the begin transaction and end transaction.
  • 5.
    Example of Transaction •A withdrawal transaction in an ATM could consist of following steps: ▫ Verify account details ▫ Accept withdrawal request ▫ Check balance ▫ Update balance ▫ Dispense money
  • 6.
    Transaction control • Thefollowing commands are used to control transactions. ▫ COMMIT − to save the changes. ▫ ROLLBACK − to roll back the changes. ▫ SAVEPOINT − creates points within the groups of transactions in which to ROLLBACK. ▫ SET TRANSACTION − Places a name on a transaction.
  • 7.
    Commit command • Thecommit command is the transactional command used to save changes invoked by a transaction to the database. • The syntax for the commit command is as follows: ▫ COMMIT; • Example : ▫ sql?>DELETE FROM CUSTOMERS WHERE AGE = 25; ▫ sql> COMMIT;
  • 8.
    Rollback command • Therollback command is the transactional command used to undo transactions that have not already been saved to the database. • The syntax for a rollback command is − ▫ ROLLBACK; • Example : ▫ SQL> DELETE FROM CUSTOMERS WHERE AGE = 25; ▫ SQL> ROLLBACK;
  • 9.
    Savepoint command • Asavepoint is a point in a transaction when you can roll the transaction back to a certain point without rolling back the entire transaction. • The syntax for a savepoint command is: ▫ SAVEPOINT SAVEPOINT_NAME;
  • 10.
    Set transaction command •The set transaction command can be used to initiate a database transaction. • For example we can specify a transaction to be read only or read write. • The syntax for a set transaction command is: ▫ SET TRANSACTION [ READ WRITE | READ ONLY ];
  • 11.
    Properties of Transactions •In order to maintain consistency in a database, before and after transaction, certain properties are followed. • These are called ACID properties. ▫ A: Atomicity ▫ C: Consistency ▫ I: Isolation ▫ D: Durability
  • 12.
    Atomicity • It meansthat the entire transaction takes place at once or doesn’t happen at all. • There is no midway i.e. transactions do not occur partially.
  • 13.
    • It involvesfollowing two operations. ▫ Abort: If a transaction aborts, changes made to database are not visible. ▫ Commit: If a transaction commits, changes made are visible. • Atomicity is also known as the ‘All or nothing rule’.
  • 14.
    Consistency • This meansthat integrity constraints must be maintained so that the database is consistent before and after the transaction. • It refers to correctness of a database.
  • 15.
    Isolation • This propertyensures that multiple transactions can occur concurrently without leading to inconsistency of database state. • Transactions occur independently without interference. • Changes occurring in a particular transaction will not be visible to any other transaction until that particular change in that transaction is written to memory or has been committed.
  • 16.
    Durability • This propertyensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk. • These updates now become permanent and are stored in a non-volatile memory. • The effects of the transaction, thus, are never lost.
  • 17.
    Transaction States • Whilethe transaction executes in a database it could be in one of the following states: ▫ Active : In this state, the transaction is being executed. This is the initial state of every transaction. ▫ Partially committed: When a transaction executes its final operation, it is said to be in a partially committed state.
  • 18.
    ▫ Failed :A transaction is said to be in a failed state if any of the checks made by the database recovery system fails. A failed transaction can no longer proceed further. ▫ Aborted: If any of the checks fails and the transaction has reached a failed state, then the recovery manager rolls back all its write operations on the database to bring the database back to its original state where it was prior to the execution of the transaction. Transactions in this state are called aborted. ▫ Committed: If a transaction executes all its operations successfully, it is said to be committed. All its effects are now permanently established on the database system
  • 20.
    Demonstrating transaction states •Consider a user making a booking for a flight over a web. • While the user is selecting the time for departure and the seat available, the transaction is said to be in active state. • When the user is making the payment for the tickets, the transaction is said to be partially commited.
  • 21.
    • While makingthe payment if the system crashes or network connection goes off, the transaction may be aborted. • Otherwise, if successful payment is made the transaction is said to be committed.