Story of transactions in sql server

726 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
726
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Story of transactions in sql server

  1. 1. Story of Transaction <ul><li>ABC company is maintaining the above table for its employees. </li></ul>EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  2. 2. <ul><li>Salary values of employees are updated now and then in this table. </li></ul><ul><li>Here 2 rows are going to be updated. </li></ul>Story of Transaction 3000 5000 EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  3. 3. <ul><li>We have the updated table with us. </li></ul>Story of Transaction EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200
  4. 4. <ul><li>One day, the system got crashed. </li></ul><ul><li>No Backup!! And what they have is just the previous table . </li></ul>Story of Transaction EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  5. 5. <ul><li>From that day on wards, they planned to track or log each changes they are making on the table. These log files could help them in these situations </li></ul><ul><li>They understood that, there are two techniques to maintain log files </li></ul>Story of Transaction
  6. 6. Technique 1: Story of Transaction Table in database EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  7. 7. Technique 1: Story of Transaction BEGIN UPDATE tbl_emp SET Salary=3000 WHERE EmpID=1000; DBMS_OUTPUT.PUT_LINE(‘Third row’); UPDATE tbl_emp SET Salary=5000 WHERE EmpID=1002; COMMIT; END; PL/SQL code Transaction Log File <T1 Starts> <T1, Row1, 3000> <T1, Row3, 5000> <T1, Commit> Deferred update EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200
  8. 8. Technique 2: Story of Transaction BEGIN UPDATE tbl_emp SET Salary=3000 WHERE EmpID=1000; DBMS_OUTPUT.PUT_LINE(‘Third row’); UPDATE tbl_emp SET Salary=5000 WHERE EmpID=1002; COMMIT; END; PL/SQL code Transaction Log File <T1 Starts> <T1, Row1, 2500, 3000> <T1, Row3, 4500, 5000> <T1, Commit> Immediate update EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200
  9. 9. <ul><li>ABC company now has the updated table and log file with them. Log files are frequently saved to safe place as its small & quick. </li></ul>Story of Transaction <ul><li>Now, If the system crashes again, let us see how ABC recovers data from log file. </li></ul>
  10. 10. Story of Transaction <T1 Starts> <T1, Row1, 3000> <T1, Row3, 5000> <T1, Commit> Have taken Deferred Update Transaction Log file Both Start and Commit is there. So it was a successful transaction EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200 EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200

×