When we talk about transactions from the database perspective, it means a set of operations treated as one operation that is indivisible. Either all the operations should succeed or none of them. The concept of a transaction is to have a unit of work that is reliable. All the database operations involved in the transaction should be treated as a unit of work.
From the application perspective, if we want to have multiple database operations treated as a single unit of work, we should wrap them in a transaction. In order to be able to use transactions, an application needs to perform the following steps:
Begin transaction.
Execute all the queries, and perform all the database operations that need to be treated as single unit of work.
If all the operations are successful, commit the transaction.
If any of the operations fail, roll back the transaction.