Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sections 17– database transactions and controlling User Access

Similar presentations


Presentation on theme: "Sections 17– database transactions and controlling User Access"— Presentation transcript:

1 Sections 17– database transactions and controlling User Access
Database Programming Sections 17– database transactions and controlling User Access 10/3/06

2 Review DDL - defines a table and changes to the table
DML - manipulates the data in a table DCL - controls who can use the table Relate the data transaction terms learned in the lesson to the DML statements learned earlier. When data is being entered, updated or deleted, mistakes can be made. The data transaction processes COMMIT, SAVEPOINT and ROLLBACK enable users to make the task of data entry easier and more efficient. Control points prevent having to correct costly mistakes or having to re-enter data. Oracle HTML DB does not allow ROLLBACKS and SAVEPOINTS, and implements an automatic COMMIT. Any time you send a transaction across Oracle HTML DB, an implicit COMMIT happens. Because the COMMIT happens, there is no way for a ROLLBACK occur. The connection from HTTP is not a persistent connection to the database. Therefore, there is no concept of doing COMMIT or ROLLBACK of DML statements. Students can learn about COMMIT and ROLLBACK concepts in this class, but using Oracle HTML DB to demonstrate a ROLLBACK, COMMIT, or SAVEPOINT is not an option. Marge Hohly

3 Transactions Allow users to make changes to data then decide whether to save or not the work. Database transactions bundle multiple steps into a logical unit. Transactions consist of one of the following: DML statements which constitute one consistent change to the data. The DML processes include INSERT, UPDATE, DELETE and MERGE one DDL statement such as CREATE, ALTER, DROP, RENAME or TRUNCATE one DCL statement such as GRANT or REVOKE Explain the concept of a transaction using the bank analogy. A bank database contains balances for various customer accounts, as well as total deposit balances for other branches. Suppose a customer wants to withdraw and transfer money from their account and deposit it into another customer's account at a different branch. There are several separate steps involved to accomplish this rather simple operation. Both bank branches want to be assured that either all steps in the transaction happen, or none of them happen and if the system crashes, the transaction is not left partially complete. Grouping the withdrawal and deposit steps into a transaction provides this guarantee. A transaction either happens completely or not at all. Marge Hohly

4 Transactions COMMIT ROLLBACK SAVEPOINT ROLLBACK TO SAVEPOINT
When user wants to save group of changes and make pending changes permanent ROLLBACK Discards changes made to database, all pending changes are discarded. SAVEPOINT Creates a marker in a transaction, which divides the transaction into smaller pieces. ROLLBACK TO SAVEPOINT Allows user to roll back the current transaction to a specified savepoint. Discards only changes after the SAVEPOINT Marge Hohly

5 Example UPDATE d_cds SET cd_number = 96
WHERE title = 'Graduation Songbook'; SAVEPOINT one INSERT INTO d_cds(cd_number, title, producer, year) VALUES(100, 'Go For It', 'The Music Man', 2004) ); SET cd_number = 101 ROLLBACK TO SAVEPOINT one COMMIT; Marge Hohly

6 u Marge Hohly

7 d Marge Hohly

8 d Marge Hohly

9 l Run command. Marge Hohly

10 P Marge Hohly

11 i Marge Hohly

12 P Marge Hohly

13 P Marge Hohly

14 P Marge Hohly

15 P Marge Hohly

16 P Marge Hohly

17 P Marge Hohly

18 P Marge Hohly

19 P Marge Hohly

20 c Marge Hohly

21 w Marge Hohly

22 p Marge Hohly

23 M Marge Hohly

24 W Marge Hohly

25 l Marge Hohly

26 u Marge Hohly

27 p Marge Hohly

28 o Marge Hohly

29 p Marge Hohly

30 p Marge Hohly

31 l Marge Hohly

32 l Marge Hohly

33 p Marge Hohly

34 p Marge Hohly

35 p Marge Hohly


Download ppt "Sections 17– database transactions and controlling User Access"

Similar presentations


Ads by Google