Database transaction is collection of SQL queries
which forms a logical one task. For transaction to
be completed successfully all SQL queries has to
Database should always remain consistent whether
transaction succeeded or failed.
Transaction is implemented in database using SQL
keyword transaction, commit and rollback.
3. Database is used to store data required by
real life application e.g. Banking,
Healthcare, Finance etc. In order to protect
data and keep it consistent any changes in
this data needs to be done in transaction
so that even in case of failure data remain
in previous state before start of transaction.
4. There are four important properties of database transactions,
represented by acronym ACID.
A stands for Atomicity, either all steps of transaction
completes or none of them.
C stands for Consistency, transaction must leave database in
consistent state even if it succeed or rollback.
I is for Isolation. Two database transactions happening at
same time should not affect each other.
D stands for Durability, means saving the data related to
5. To understand database transaction better let's see a
real life example of transaction in database. For
this example we will assume we have an Account
table which represent a Bank Account and we will
transfer money from one account to another
select balance from Account where Account Number='9001';
select balance from Account where Account Number='9002';
update Account set balance=balance-900 here Account
update Account set balance=balance+900 here Account
commit; //if all SQL queries succeed
rollback; //if any of SQL queries failed or error