Database Programming Sections 14– database transactions and controlling User Access

Preview:

Citation preview

Database Programming

Sections 14– database transactions and controlling User Access

Marge Hohly 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

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

Marge Hohly 4

Transactions COMMIT

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

Marge Hohly 6

ExampleUPDATE d_cdsSET cd_number = 96WHERE title = 'Graduation Songbook';SAVEPOINT oneINSERT INTO d_cds(cd_number, title, producer, year)VALUES(100, 'Go For It', 'The Music Man', 2004) );UPDATE d_cdsSET cd_number = 101ROLLBACK TO SAVEPOINT oneCOMMIT;

Marge Hohly 7

Marge Hohly 8

Marge Hohly 9

Marge Hohly 10

Marge Hohly 11

Marge Hohly 12

Marge Hohly 13

Marge Hohly 14

Marge Hohly 15

Marge Hohly 16

Marge Hohly 17

Marge Hohly 18

Terminology

Transaction Commit Savepoint Rollback Read consistency Locks

Marge Hohly 19

Recommended