Upload
hanuman
View
579
Download
2
Embed Size (px)
Citation preview
EmpID EmpName Salary
1000 Tom 2500
1001 Jerry 3000
1002 Mickey 4500
1003 Frank 1200
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
• 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 3000
1001 Jerry 3000
1002 Mickey 5000
1003 Frank 1200
• We have the updated table with us.
Story of Transaction
• 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
• 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
Technique 1:
Story of Transaction
EmpID EmpName Salary
1000 Tom 2500
1001 Jerry 3000
1002 Mickey 4500
1003 Frank 1200
Table in database
Technique 1:
Story of Transaction
EmpID EmpName Salary
1000 Tom 2500
1001 Jerry 3000
1002 Mickey 4500
1003 Frank 1200
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>
EmpID EmpName Salary
1000 Tom 3000
1001 Jerry 3000
1002 Mickey 5000
1003 Frank 1200
Deferred update
Technique 2:
Story of Transaction
EmpID EmpName Salary
1000 Tom 2500
1001 Jerry 3000
1002 Mickey 4500
1003 Frank 1200
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>
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
Immediate update
• 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.
Story of Transaction
EmpID EmpName Salary
1000 Tom 2500
1001 Jerry 3000
1002 Mickey 4500
1003 Frank 1200
<T1 Starts>
<T1, Row1, 3000>
<T1, Row3, 5000>
<T1, Commit>
Have taken Deferred Update
Transaction Log file
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
Both Start and Commit is there. So it was a successful
transaction
EmpID EmpName Salary
1000 Tom 3000
1001 Jerry 3000
1002 Mickey 5000
1003 Frank 1200