In short, a database transaction is a sequence of multiple operations performed on a database, and all served as a single logical unit of work — taking place wholly or not at all. In other words, there's never a case that only half of the operations are performed and the results saved.
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 some sort of a database program. A transaction is the propagation of one or more changes to the database.
Three DBMS transactions types are Base on Application Areas, Action, & Structure.
A database transaction delimits a set of database operations (i.e. SQL statements), that are processed as a whole. Database operations included inside a transaction are validated or canceled as a unique operation. The database server is in charge of data concurrency and data consistency .
A transaction is a unit of work that you want to treat as "a whole." It has to either happen in full or not at all.
A classical example is transferring money from one bank account to another. To do that you have first to withdraw the amount from the source account, and then deposit it to the destination account. The operation has to succeed in full. If you stop halfway, the money will be lost, and that is Very Bad.
In modern databases transactions also do some other things - like ensure that you can't access data that another person has written halfway. But the basic idea is the same - transactions are there to ensure, that no matter what happens, the data you work with will be in a sensible state. They guarantee that there will NOT be a situation where money is withdrawn from one account, but not deposited to another.
A transaction is a way of representing a state change. Transactions ideally have four properties, commonly known as ACID:
See the Wikipedia ACID entry for more details.
Although this is typically applied to databases, it doesn't have to be. (In particular, see Software Transactional Memory.)
Here's a simple explanation. You need to transfer 100 bucks from account A to account B. You can either do:
accountA -= 100;
accountB += 100;
or
accountB += 100;
accountA -= 100;
If something goes wrong between the first and the second operation in the pair you have a problem - either 100 bucks have disappeared, or they have appeared out of nowhere.
A transaction is a mechanism that allows you to mark a group of operations and execute them in such a way that either they all execute (commit), or the system state will be as if they have not started to execute at all (rollback).
beginTransaction;
accountB += 100;
accountA -= 100;
commitTransaction;
will either transfer 100 bucks or leave both accounts in the initial state.
"A series of data manipulation statements that must either fully complete or fully fail, leaving the database in a consistent state"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With