A database transaction is a collection of SQL queries that form a logical task. For the transaction to complete successfully, all SQL queries must run successfully. Transactions are implemented using SQL keywords like transaction, commit, and rollback to ensure the database remains consistent whether the transaction succeeds or fails. Transactions have four key properties (ACID) to keep the database secure and data accurate.
1 of 7
Download to read offline
More Related Content
Transactional database
2.
Database transaction is collection of SQL queries
which forms a logical one task. For transaction to
be completed successfully all SQL queries has to
run successfully
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
transaction.
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
account.
start transaction
select balance from Account where Account Number='9001';
select balance from Account where Account Number='9002';
update Account set balance=balance-900 here Account
Number='9001' ;
update Account set balance=balance+900 here Account
Number='9002' ;
commit; //if all SQL queries succeed
rollback; //if any of SQL queries failed or error