Junior — Middle
Explain what a transaction is in a database management system and how it ensures data integrity.
sobes.tech AI
Answer from AI
A transaction in a database management system is a sequence of operations that are executed as a single unit. It ensures data integrity by following the ACID principles:
- Atomicity: all operations of the transaction are completed fully or not at all.
- Consistency: the transaction transforms the database from one valid state to another.
- Isolation: concurrent transactions do not affect each other.
- Durability: once committed, the changes made by the transaction are permanent, even in case of failures.
For example, when transferring money between accounts, a transaction guarantees that the debit from one account and the credit to another will either both happen or both not happen, preventing loss or duplication of funds.