A transaction in a database management system (DBMS) is a piece of work done on a database. Because a transaction is an atomic unit, it can either be completed entirely or not at all. Desirable properties of Transaction in DBMS are commonly known as ACID properties.
The process known as transaction control enables you to govern how transactions affect your database. It enables you to either roll back the changes made during a transaction in the event of an error or commit the changes made during a transaction to the database.
Here I present you some examples of how transaction control is used in a DBMS:
- Transferring money from one bank account to another:
You can think of this as a two-step process:
- Step 1: Deduct the money from the source account
- Step 2: Add the money to the destination account
To make sure that the accounts remain in a consistent state, you would want to roll back the transaction if either of these stages fails.
- Updating a customer’s address in a database:
Consider updating a database with a customer’s address. There may be numerous tables where the address needs to be updated (e.g., the “customers” table and the “orders” table). To keep the database in a consistent state if one of the updates fails, you would want to roll back the transaction.
- Printing a report:
Consider printing a report that requires data queries from several different tables. You may want to roll back the transaction if the query fails for any reason in order to prevent the report from being generated with inaccurate or missing data.
These are just a few instances of how a DBMS uses transaction control.
Happy Learning!