CH-14 Database Transactions PDF
CH-14 Database Transactions PDF
CH-14 Database Transactions PDF
Page 1 of 4
Each transaction, generally, involves one or more data manipulation language (DML) statements (such as INSERT,
DELETE or UPDATE) and ends with either a COMMIT to make the changes permanent or ROLLBACK to undo the
changes. The database transaction must be handled in a way so that their integrity is maintained.
2 Briefly explain the system view of the transaction.
Ans. The system (data base software) views a transaction as a logical sequence of read and write operations, where
1. Read (X) – operation brings data item X from database to an area in the main memory where the transaction
is executing.
2. Write (X) – operation transfers data item X from transaction’s main memory area to the database file.
3 What is the function of redo and undo logs?
Ans. DBMS maintains special logs to perform redo and undo operations if required.
A storage area that holds copies of data modified by active transactions. By default, this area is physically part of
the system tablespace. Redo log stores correct data written by incomplete transactions. And used for redo
operations.
4 Discuss briefly the ACID properties and their importance in transaction handling?
Ans. Atomicity –This property ensures that either all operations of the transaction are reflected properly in the
database, or none are. Atomicity ensures either all-or-none operations of a transaction are carried out.
Consistency –This property ensures that the database remains in a consistent state before the start of
transaction and after the transaction is over (whether successfully or unsuccessfully).
Isolation –Isolation ensures that each executing transaction execution in isolation i.e., is unaware of other
transactions executing concurrently in the system.
Durability –This property ensures that after the successful completion of a transaction i.e., when a transaction
COMMITs, the changes made by it to the database persist i.e., remain in the database irrespective of other
system failures.
5 What are the various advantages and limitations of serial execution of transactions?
Ans. Advantages
1. Correct execution, i.e., if the input is correct then output will be correct.
2. Fast execution since all the resources are available to the active.
Limitation
1. The worst thing about serial execution is very inefficient resource utilization.
2. Waiting time time is high as only one transaction executes at a time.
6 Why do we use ROLLBACK statement? Explain in brief with the help of an example.
Ans. The ROLLBACK statement is used to undo transactions that have not already been saved to the database.
The ROLLBACK command can only be used to undo transactions since the last COMMIT or ROLLBACK command
was issued.
The syntax for ROLLBACK command is as follows:
ROLLBACK;
Example:
Consider the CUSTOMERS table having the following records:
+----+------------+-------+-----------------+--------------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+------------+-------+------------------+-------------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Following is the example, which would delete records from the table having age = 25 and then ROLLBACK the
changes in the database.
SQL> DELETE FROM CUSTOMERS
WHERE AGE = 25;
Page 2 of 4
SQL> ROLLBACK;
As a result, delete operation would not impact the table and SELECT statement would produce the following
result:
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Page 4 of 4