Transaction: Transaction is agroup of sql (DML) statements which are used to perform certain combination ofoperations like write, update etc. into one unit to make the consistency ofdata. They are used to perform multiple actions if and only if all theoperations can be performed else none of the action or operation should not be doneand the database should not affect i.
e; the transaction is ROLLBACK. If all theoperations are performed successfully than it will be save to database byissuing the COMMIT command. There is a Transaction log which are used to makethe database to original state in case of failure occurs. With transactionssupports ACID properties. The real scenarios where Transactions are used areBank data base for money transactions, railway reservation etc. Transaction is an automatic work with respectto recovery and consistency. Transactions are useful when you’re modifying two tables that you don’twant out of sync.
The classic example is a debit/credit system for a bank,where money is moved from one account to another: Here transaction is performedusing TRY catch block. BEGIN TRANSACTION;BEGIN TRYUPDATE account SET total=total+5000.0 WHERE account_id=1337;UPDATE account SET total=total-5000.0 WHERE account_id=45887;COMMIT TRANSACTION END TRYBEGIN CATCHROLLBACK TRANSACTIONEND CATCH GOIf something happened between the two updates, this bank would lose $5000.00.
But, when wrapped in a transaction block, the initial update is rolled back,even if the server crashes. Transaction Processing:Transaction processing gives ascheme which is used to check the progress and controls the execution oftransaction programs. Transaction processing mainly used in mission-criticalapplications which requires large amount of parallel users with minimum downtime. Proper use of Transaction Processing resultsthe controlling the execution of several applications which are executingparallel.
Transaction processing ensures the ACID properties over differentdatabases this can be done by using two-phase COMMIT. Transaction processingsystem is best used if an application requires online access and also if thereis a modification on different databases. Local Transaction: When thetransaction is limited to only single database or resource is called LocalTransaction and all the operations will commit at the end of the transaction. Distributed Transaction: Unlike to local transaction whichare limited to specific resource distributed transactions extend acrossmultiple databases or resources.
It is similar to local transaction where atthe end of the transaction should be either committed or roll backed. If wehave a situation where network failure occurs then but unfortunately in placeof rollback all the transactions the data in one of the database or resource iscommitting this can happen due to many reasons to minimize these type of riskdistributed transaction uses TWO –PHASE COMMIT process. Implicit transaction containsonly one statement of either INSERT, UPDATE, DELETE etc.
After connecting tothe database then if we perform or execute any DML statements then changes aremade and saved to database automatically. This happens since the connection isin auto commit transaction mode. If you don’t want to save any changes untilunless you specifies the COMMIT or ROLLBACK then we can use ImplicitTransaction. Using Implicit Transaction the transactions remains in effectuntil the user issues the COMMIT or ROLLBACK commands.Explicit transaction containsmultiple statements with BEGIN indicates start the transaction and END indicatesend the transaction. Using explicit transaction user is controlling when thetransaction is going to start and when it should ends. These are also calleduser-defined transactions.