Junior — Middle
Can you explain what is meant by a transaction in databases?
sobes.tech AI
Answer from AI
A transaction in databases is a sequence of operations that is executed as a single unit. The main idea is that either all operations of the transaction are successfully completed, or none of them are applied (atomicity).
Transactions ensure four key properties (ACID):
- Atomicity: all operations within a transaction are either fully completed or not executed at all.
- Consistency: after the transaction completes, the database remains in a correct state.
- Isolation: concurrent transactions do not affect each other.
- Durability: after a transaction is committed, the changes are saved even in case of failures.
Example: when transferring money between bank accounts, a transaction guarantees that the debit from one account and the credit to another happen together, to prevent loss or creation of money.