In database terms, a transaction is a collection of database operations that represents a unit of work.
A transaction lifespan refers to the period of its initiation and completion, and includes the entire sequence of operations that make up the unit of work:
1.
Start: When the transaction begins, typically marked by BEGIN command in SQL.
2.
Execution: This includes one or more individual operations (query), often they are update and create commands, however it could be a read command.
3.
Commit: When all operations succeed and represent a valid change, the transation is committed. The changes are now applied.
4.
Rollback (Optional): If any operation fails or invalid, it's rolled back. It undoes all changes within the transaction.
2400 x 1260, 76.3 KB, JPG
A transaction is based on the concept of Atomicity (ACID), ensure all operations within a transaction happen entirely or not at all.
Read operations can also be transactions
For many cases, they are used for create, update or delete operations, however, in some other cases. a read operation that requires consistent data in a specific timestamp could also be implemented within a transaction (e.g., generating reports).