• Like
Story of transactions in sql server
Upcoming SlideShare
Loading in...5
×

Story of transactions in sql server

  • 531 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
531
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
7
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Story of Transaction
    • ABC company is maintaining the above table for its employees.
    EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  • 2.
    • Salary values of employees are updated now and then in this table.
    • Here 2 rows are going to be updated.
    Story of Transaction 3000 5000 EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  • 3.
    • We have the updated table with us.
    Story of Transaction EmpID EmpName Salary 1000 Tom 3000 1001 Jerry 3000 1002 Mickey 5000 1003 Frank 1200
  • 4.
    • One day, the system got crashed.
    • No Backup!! And what they have is just the previous table .
    Story of Transaction EmpID EmpName Salary 1000 Tom 2500 1001 Jerry 3000 1002 Mickey 4500 1003 Frank 1200
  • 5.
    • 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
    • They understood that, there are two techniques to maintain log files
    Story of Transaction
  • 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. 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. 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.
    • ABC company now has the updated table and log file with them. Log files are frequently saved to safe place as its small & quick.
    Story of Transaction
    • Now, If the system crashes again, let us see how ABC recovers data from log file.
  • 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