Download presentation
Presentation is loading. Please wait.
1
Data creation and destruction Inserting into a table Deleting from a table Modifying values in a table Other commonly used features Views Transactions and triggers Summary Outline
2
A transaction identifies an elementary unit of work carried out by an application, to which we wish to allocate particular characteristics of reliability and isolation. A system that makes available mechanisms for the definition and execution of transactions is called a transaction processing system. Transactions are initiated with any SQL statement that modifies the database. Transactions
3
A transaction can be defined syntactically: each transaction, irrespective of the language in which it is written, is enclosed whthin two commands: begin transaction end transaction Within the transaction code, two particular instructions can appear commit work rollback work Transactions
4
An example of transaction is given in the following code: begin transaction X := x – 10; Y := y + 10; Commit work; end transaction Transaction example
5
Active databases An active database system is a DBMS that supports an integrated subsystem for the definition and management of production rules. The rules follow the event – condition – action paradigm: each rule reacts to some events, evaluates a condition and, based on the truth value of the condition, might carry out an action. The execution of the rules happens under the control of an autonomous subsystem, known as the rule engine, which keeps track of the events that have occurred and schedules the rules for execution. One of the active rules called triggers.
6
Triggers (on tables) The creation of triggers is part of the DDL. Maintain data integrity Associated with a table Event-condition-action Wait for a table event On event, evaluate condition If condition is true, execute action Table-level vs. row-level X before after insertion deletion update
7
Table-level trigger Works with entire table Action evaluated with respect to before image or after image, prior to commit Row-level trigger Works with entire table and a buffer of changes New - tuples that were inserted Old - tuples that were deleted Update is insertion + deletion Trigger iterates through buffer of changes Action evaluated with respect to before image or after image, prior to the work being committed Level of Trigger
8
The Person table associates Names and Cities. INSERT INTO Person(Name, City) VALUES (Jill, Cork) Before insertion, SELECT COUNT(*) will result in 3 After insertion, SELECT COUNT(*) will result in 4 Table-level Insertion Event Joe Susan Dublin Cork Juan Name City Joe Susan Dublin Cork Juan Name City JillCork BeforeAfter
9
The Person table associates Names and Cities. DELETE FROM Person WHERE City = ‘Cork’; SELECT COUNT(*) FROM Person; 3 in before image, 1 in after image Table-level Deletion Event Joe Susan Dublin Cork Juan Name City JoeDublin Name City BeforeAfter
10
The Person table associates Names and Cities. UPDATE Person SET City = ‘Dublin’ WHERE City = ‘Cork’; SELECT Name FROM Person WHERE City=‘Dublin’; 3 in before image, 3 in after image Table-level Update Event Joe Susan Dublin Cork Juan Name City Name City BeforeAfter Joe Susan Dublin Juan
11
PL/SQL program Example: At most 100 people can live in Dublin After update/insert into Person DECLARE Declare Variables C INTEGER; BEGIN Body of Trigger SELECT COUNT(Name) INTO C FROM Person WHERE City = ‘Dublin’; IF (C > 100) THEN RAISE_APPLICATION_ERROR(-20000, ‘too many in Dublin’); END IF; END Oracle Table-level Trigger Body
12
The Person table associates Names and Cities. INSERT INTO Person(Name, City) VALUES (Jill, Cork) Row-level Insertion Event Joe Susan Dublin Cork Juan Name City JillCork Name City Buffer OldNew Joe Susan Dublin Cork Juan Name City JillCork BeforeAfter
13
The Person table associates Names and Cities. DELETE FROM Person WHERE City = ‘Cork’; Row-level Deletion Event Joe Susan Dublin Cork Juan Name City Name City Buffer OldNew JoeDublin Name City BeforeAfter SusanCork Juan
14
The Person table associates Names and Cities. UPDATE Person SET City = ‘Dublin’ WHERE City = ‘Cork’; Row-level Update Event Joe Susan Dublin Cork Juan Name City Name City Name City Buffer OldNew Joe Susan Dublin Juan Name City BeforeAfter SusanDublin Juan SusanCork Juan
15
Notification an active database may be used to monitor Enforce integrity constraints Business roles maintenance of derived data Maintain the derived attribute whenever individual tuples are changed Potential Applications
16
Potentially infinite loop Trigger A: On insertion into Person, insert into Population Trigger B: On insertion into Population, insert into Person Mutating tables Trigger A: On insertion into Person, insert into Person! Disallowed! Trigger cannot make changes to table that trigger is defined on Trigger Gotchas
17
Schema definition CREATE TABLE CREATE VIEW ALTER DROP Queries SELECT Summary
18
Modifications INSERT DELETE UPDATE Transaction Management COMMIT ROLLBACK Active Database Trigger Summary, cont.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.