A complete collection of Database management system notes,tools and project..

Menu

Sunday, 9 February 2014

A Transaction is a set of changes that must all be made together.It is a collection of Operations that form a single logical unit of work.It must be either completed or entirely aborted to ensure the consistency and integrity of database.For Example - A transfer of money from one bank account to another requires two changes to the database both must succeed or fail together. Consider the example - You are working on a system for a bank.

A customer goes to the ATM and instructs it to transfer RS 1000 from saving to a checking account.This simple transaction requires 2 steps.

1. Subtracting the money from the savings account balance.

2. Adding the money to the checking account balance.

The code to create this transaction will require two updates to the database. There will be two SQL statements-one UPDATE command to decrease the balance in savings and a second UPDATE command to increase the balance in the checking account.Both changes must be made successfully .Thus a transaction is defined as a set of changes that must be made together.

PROCESS OF TRANSACTION-

The transaction is executed as a series of reads and writes of database objects.

1.READ OPERATION-

To read a database object, it is first brought into main memory from disk and then its value is copied into a program variable.

2.WRITE OPERATION-

To write a database object,memory copy of the object is first modified and then written to disk.

PROPERTIES OF TRANSACTION( ACID PROPERTIES )

ACID (Atomicity, Consistency, Isolation, Durability) is a set of properties that guarantee that database transactions are processed reliably.

A- Atomicity

C- Consistency

I- Isolation

D- Durability

1.Atomicity-(all or nothing): A transaction is said to be atomic if a transaction always executes all its action in one step or not executes any action at all. EG-Assume that a transaction attempts to subtract 20 from A and add 20 to B. This is a valid transaction, since the data continue to satisfy the constraint after it has executed. However, assume that after removing 20 from A, the transaction is unable to modify B. If the database retained A's new value, atomicity requires that both parts of this transaction,is either completed or aborted.

2.Consistency(No violation of Integrity Constraints): A transaction must preserve the consistency of a database. EG- The sum of A and B must be same after and before the transaction.

3. Isolation-(concurrent changes invisibles):The transaction must behave as if they are executed in isolation.In other words if transaction are executed concurrently the result must be same.EG-Consider two transactions. T1 transfers 50 from A to B. T2 transfers 50 from B to A. Combined, there are four actions:

T1 subtracts 50 from A.

T1 adds 10 to B.

T2 subtracts 50 from B.

T2 adds 10 to A.

If these operations are performed in order, isolation is maintained otherwise there will be an error.

4.Durability-(committed update persist):The effect of complete or committed transaction should persist even after a crash or power failure.