Sections 17– database transactions and controlling User Access Database Programming Sections 17– database transactions and controlling User Access 10/3/06
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
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
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
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
u Marge Hohly
d Marge Hohly
d Marge Hohly
l Run command. Marge Hohly
P Marge Hohly
i Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
P Marge Hohly
c Marge Hohly
w Marge Hohly
p Marge Hohly
M Marge Hohly
W Marge Hohly
l Marge Hohly
u Marge Hohly
p Marge Hohly
o Marge Hohly
p Marge Hohly
p Marge Hohly
l Marge Hohly
l Marge Hohly
p Marge Hohly
p Marge Hohly
p Marge Hohly