You logged in into your bank's site and types your account number.
Later you typed your friend's name and his account number
Later types the amount and clicks on TRANSFER button.
Later??? Rs. 1500 /- TRANSFERS into your friend's account.
Now lets see this process in DBMS's point of view.
YOu entered some money (Rs 1500). The DBMS checks whether the mentioned money is available in your account or not.Assume that you have some 3000 in your account.
If available then it checks the reciepient's Account (Assume that he has Rs. 200 in his account)
Later the DBMS reduces your amount to Rs 1500 and Adds that 1500 to your friend's account.
And makes his account balance as Rs 1700 ( 200 + 1500).
Then shows you a message, something like "TRANSACTION COMPLETED"
yes, this is an example of Transaction.
A transaction is an execution of a user program and is seen by the DBMS as a series or list of actions. (or simply we can remember it as " A transaction is nothing but a List of Actions". These actions include the reading and writing of database.
ACID Properties (important) :
These are the properties that a transaction should possess in order to avoid failures during concurrent access to a database. The ACID is an acronym which stands for Atomicity, Consistency, Isolation, Durability. Now lets have a look at these properties in detail. Ofcourse, for beginers these all may look same and confusing, read them two or three times. then you can get the exact meanings and differences among them...
- Atomicity : It ensures that the transaction either is executed completely or not at all. Incomplete transaction consequences are not entertained, check an example
- Assume that Shivani has Rs. 500/- in her account and Palvi has Rs. 200/- in her account. Now Shivani transfers an amount of Rs. 50/- to Palvi. A transaction debits the amount from shivani's account, but befrore it could be credited to palvi, if there is a failure, then transaction would stop. So finally Shivani loses Rs. 5o but palvi cant get the amount. This leaves the data in an inconsistent state. If there is a failure during transaction execution , then measures must be taken to get back the data in a form which was in, before transaction (I mean, the 50 shouldnt be deducted from Shivani's account in our case). This is taken care of by transaction management component.
- Consistency : The data in the database must always be in a consistent state. A transaction occurred on a Consistent data should end with the data with another Consistent stage after completion of that transaction. Take the above case, the total of the amounts of Shivani and Palvi are (500+200) is Rs 700/- So, after the Transaction completed, the total amount should be same. i.e., (450+250 = 700). Ofcourse, in intermediate stage, where the amount is deducted from Shivani's account but not yet credited to Palvi, the total would not be same. It is the responsibility of DBMS.
- Durability : Durability ensures that the data remains in a consistent state even after the FAILURE. (This is ensured by keeping copy of the old data in the Disk, till the transaction is COMPLETED). I mean, if shivani is transfering money to Palvi. The money is deducted frm Shivani's account and power gone (before adding the MONEY to palvi's account). Then our DBMS shouldn't save that transaction. This is called Durability.
- Isolation : All transaction must run in Isolation from one another. I mean, each and every transaction should be kept unaware of other transactions and execute independently. The intermediate results shouldnt be available to other transactions.
No comments:
Post a Comment