Vous êtes sur la page 1sur 2

http://www.infotechcomputer.

in

‘Chapter 14 – Database Transactions’


Q. What is a Transaction ?
Ans. A transaction is a Logical unit of work that must succeed or fail in its entirety. A transaction is an atomic
operation which may not be divided into smaller operations.

Q What are the basic Transaction Properties ?


Ans. Four Basic Properties of Transaction are Atomicity, Consistency, Isolation, Durability. These are also
called as ACID Properties of Transaction.
Atomicity - This property ensures "All-or-None" operations are carried out in a transaction.

Consistency - This property implies that if the database was in a consistent state before the start of transaction
then upon termination of transaction the database will also be in a consistent state.

Isolation - this property implies that each transaction is unaware of other transactions executing concurrently in
the system.

Durability - This property of a transaction ensures that after the successfull completion of a transaction the
change made by it to the database persist even if there are system failures.

Q. What is Commit ?
Ans. the commit statement or commit work statement will save all of the changes made by the transaction. It
closes the current transaction and starts a new one.

Q. What is Rollback ?
Ans. This statement will discard or undo the changes made by the transaction and starts a new transaction. it
will undo the transaction to its starting point. Rollback can be of two types
1. Complete Rollback - it will undo the transaction to its starting point
2. Partial Rollback - it will undo the transaction to the specified savepoint.

Q What is a savepoint ?
Ans. Savepoints are special opeartions that allow you to divide the work of a transaction into different segments.
in case of a failure we can execute rollbacks to the savepoint only, through ROLLBACK to SAVEPOINT
command. These are also called as checkpoints.

INFOTECH Computer Education, Kishangarh (Raj)  9829171122 Page 1


http://www.infotechcomputer.in

Q. What is set autocommit ?


Ans. By default My sql has autocommit on, which means if we do not start a transaction explicitly through a
begin or start transaction command, then every statement is considered one transaction and is committed
automatically.

To check the current setting of autocommit we have to issue the following command
select @@autocommit;
to set the autocommit we have to issue the following command
set autocommit = 0 or set autocommit =1 (by default on)

Practical

1. set autocommit=0

2. create table newraju(roll int,name char(20));

3. start transaction

4. insert into newraju values(101,'raju');

5. insert into newraju values(102,'ramu');

6. insert into newraju values(103,'golu');

7. savepoint s1

8. insert into newraju values(104,'monu');

9. insert into newraju values(105,'ranu');

10. insert into newraju values(106,'radha');

11. rollback - it will remove all of the records from table

or

12. rollback to s1 - it will remove only 104,105 and 106 which are inserted after the savepoint s1

or

13. commit - it will save all of the 6 records permanently

INFOTECH Computer Education, Kishangarh (Raj)  9829171122 Page 2

Vous aimerez peut-être aussi