MySQL - Transactions
Transaction is a group of queries or operations performed at a time on database. Transaction in terms of database is related to commit the results over disk or rollback the results in case of failure. Sometime it is necessary to either run all the queries or no single query.
The properties of a transaction in MySQL are abbreviated as ACID (Atomicity, consistency, isolation and durability).
Lets take a table containing records of an Account :
AccountNumber | AccountantName | AccountBalance | AccountBranch | AccountBank |
---|---|---|---|---|
1 | Nirupam | 562552 | Hyderabad | SOS Bank |
2 | Yaksh | 96554 | Kakinada | POP Bank |
3 | Dakshya | 21556 | Vijayawada | LOL Bank |
4 | Nirakshith | 65423 | Sulthanabad | DOT Bank |
Now,we will perform TRANSACTIONS on this table and check out the results :
START Transaction;
UPDATE accountrecord SET AccountBalance=AccountBalance- 1500 where AccountNumber = 1;
UPDATE accountrecord SET AccountBalance=AccountBalance+ 1500 where AccountNumber = 2;
COMMIT;
The result will be produced as follows :
AccountNumber | AccountantName | AccountBalance | AccountBranch | AccountBank |
---|---|---|---|---|
1 | Nirupam | 561052 | Hyderabad | SOS Bank |
2 | Yaksh | 98054 | Kakinada | POP Bank |
Example :
START Transaction;
UPDATE accountrecord SET AccountantName="Nynika" where AccountBank = "SOS BANK" ;
COMMIT;
The result will be produced as follows :
AccountNumber | AccountantName | AccountBalance | AccountBranch | AccountBank |
---|---|---|---|---|
1 | Nynika | 561052 | Hyderabad | SOS Bank |
MySQL - Grant_ Revoke Privilege
posted on 2019-11-26 23:15:04 - mysql Tutorials