0% found this document useful (0 votes)
24 views

Lesson10-Transactions and Transaction Management in SQL

Uploaded by

John Jeavons
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lesson10-Transactions and Transaction Management in SQL

Uploaded by

John Jeavons
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10 Lesson 10: Transactions and Transaction Management in

SQL
What is a Transaction?

A transaction is a unit of work that is performed against a database. Transactions are units or
sequences of work accomplished in a logical order, whether in a manual fashion by a user or
automatically by an application.
A transaction is the propagation of one or more changes to the database. For example, creating a
record, updating a record, or deleting a record from a table. It is important to control these
transactions to ensure the data integrity and to handle database errors.
Many SQL queries can be lumped together and then executed together as a part of a single
transaction.
Transaction states

The various states of a Database Transaction are listed below

State Transaction types

Active State A transaction enters into an active state when the execution process
begins. During this state read or write operations can be performed.

Partially A transaction goes into the partially committed state after the end of a
Committed transaction.

Committed State A transaction is in committed state, after it has already completed its
execution successfully. Moreover, all of its changes are recorded to the
database permanently.

Failed State A transaction is in failed state when any one of the checks fails or if the
transaction is aborted while it is in the active state.

Terminated State A transaction is in terminated state when certain transactions which are
leaving the system can't be restarted.

Properties of Transactions

Transactions have the four standard properties, usually referred to by the acronym ACID.
Atomicity
Either all operations in a transaction are carried out or none are. The meaning is the transaction
cannot be subdivided, and hence, it must be processed in its entirety or not at all. Users should not
have to worry about the effect of incomplete transactions in case of any system crash occurs.

Consistency
The database must remain in a consistent state after any transaction. No transaction should have any
adverse effect on the data residing in the database. If the database was in a consistent state before the
execution of a transaction, it must remain consistent after the execution of the transaction as well.

Isolation

1
In DBMS system, where many transactions are executed simultaneously and in parallel, each of
the transactions will be carried out and executed as if it is the only transaction in the system. Thus,
the execution of one transaction should not affect the execution of the other transactions. To enforce
this concept DBMS has to maintain certain scheduling algorithms. One of the scheduling algorithms
used is Serial Scheduling.

Durability
Durable means the changes are permanent. Once a transaction is committed, no subsequent
failure of the database can reverse the effect of the transaction.

If the system crashes before the changes made by a completed transaction are written to disk, then
it should be remembered and restored during the system restart phase.

If the transaction is interrupted in the middle way it leaves the database in the inconsistency
state. These types of transactions are called as partial transactions. Partial transactions should be
avoided in order to maintain consistency of a database. To reverse the actions done by the partial
transactions, DBMS maintains certain log files. Each and every moment of disk writes are recorded
in this log before they are reflected to disk. These are used to undo the operations done when the
system failure occurs.

Transactional Control Commands


Transactional control commands are only used with the DML Commands such as - INSERT,
UPDATE and DELETE only. They cannot be used with DDL commands because these operations
are automatically committed in the database. 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.

You might also like