mysql transactions
DESCRIPTION
MySQL Transactions - Definition - Sample scenario - Properties (ACID) - Syntax - ExampleTRANSCRIPT
![Page 1: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/1.jpg)
MySQL TransactionsReggie Niccolo Santos
UP ITDC
![Page 2: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/2.jpg)
Outline
What are transactions? Sample scenario Properties (ACID) Syntax Example
![Page 3: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/3.jpg)
What are transactions?
Sequential group of DML statements, which is performed as if it were one single work unit
Will never complete unless each individual operation within the group is successful. If any operation within the transaction fails, the entire transaction will fail
![Page 4: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/4.jpg)
What are transactions?
Begins with the first executable SQL statement
Ends when it is committed or rolled back, either explicitly with a COMMIT or ROLLBACK statement or implicitly when a DDL statement is issued
![Page 5: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/5.jpg)
Sample Scenario
Suppose a bank customer transfers money from his savings account (SB a/c) to his current account (CA a/c), the statement will be divided into four blocks:
Debit SB a/c Credit CA a/c Record in Transaction Journal End Transaction
![Page 6: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/6.jpg)
Sample Scenario
The SQL statement to debit SB a/c is as follows:
UPDATE sb_accountsSET balance = balance - 1000WHERE account_no = 932656;
![Page 7: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/7.jpg)
Sample Scenario
The SQL statement to credit CA a/c is as follows:
UPDATE ca_accountsSET balance = balance + 1000WHERE account_no = 933456;
![Page 8: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/8.jpg)
Sample Scenario
The SQL statement for recording in the transaction journal is as follows:
INSERT INTO journal VALUES (100896, 'Transaction on Benjamin Hampshair a/c', '26-AUG-08' 932656, 933456, 1000);
![Page 9: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/9.jpg)
Sample Scenario
The SQL statement for End Transaction is as follows:
COMMIT WORK;
![Page 10: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/10.jpg)
Properties (ACID)
Atomicity Ensures that all operations
within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure and previous operations are rolled back to their former state
![Page 11: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/11.jpg)
Properties (ACID)
Consistency Ensures that the database
properly changes states upon a successfully committed transaction
![Page 12: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/12.jpg)
Properties (ACID)
Isolation Enables transactions to operate
independently of and transparent to each other
![Page 13: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/13.jpg)
Properties (ACID)
Durability Ensures that the result or effect
of a committed transaction persists in case of a system failure
![Page 14: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/14.jpg)
Syntax
START TRANSACTION [transaction_characteristic [, transaction_characteristic] ...]
transaction_characteristic: WITH CONSISTENT SNAPSHOT | READ WRITE | READ ONLY
BEGIN [WORK]COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
SET autocommit = {0 | 1}
![Page 15: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/15.jpg)
Example
START TRANSACTION;
SELECT @A:=SUM(salary) FROM employee_salary WHERE type=1;
UPDATE salary_report SET summary=@A WHERE type=1;
COMMIT;
![Page 16: MySQL Transactions](https://reader033.vdocument.in/reader033/viewer/2022061223/54c4d0674a7959ff128b45a6/html5/thumbnails/16.jpg)
References Http://www.tutorialspoint.com/mysql/mysql-transa
ctions.htm Http://www.w3resource.com/mysql/mysql-transacti
on.php