Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.

Slides:



Advertisements
Similar presentations
Active database concepts
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Chapter 23 Database Security and Authorization Copyright © 2004 Pearson Education, Inc.
1 Constraints, Triggers and Active Databases Chapter 9.
Copyright © 2004 Pearson Education, Inc.. Chapter 9 More SQL: Assertions, Views, and Programming Techniques.
Chapter 7 Notes on Foreign Keys Local and Global Constraints Triggers.
Jennifer Widom Constraints & Triggers Triggers – Introduction.
SQL Constraints and Triggers
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Triggers Database Management System Design Saba Aamir Computing and Software McMaster University.
Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Chapter 7 Triggers and Active Databases. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2 Trigger Overview Element of the database schema.
Copyright © 2004 Pearson Education, Inc.. Chapter 1 Introduction and Conceptual Modeling.
 Data creation and destruction  Inserting into a table  Deleting from a table  Modifying values in a table  Other commonly used features  Views 
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Database Systems More SQL Database Design -- More SQL1.
Copyright © 2004 Pearson Education, Inc.. Chapter 19 Database Recovery Techniques.
Cs3431 Triggers vs Constraints Section 7.5. cs3431 Triggers (Make DB Active) Trigger: A procedure that starts automatically if specified changes occur.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 157 Database Systems I SQL Constraints and Triggers.
Copyright © 2004 Pearson Education, Inc.. Chapter 17 Introduction to Transaction Processing Concepts and Theory.
Chapter 7 Constraints and Triggers Spring 2011 Instructor: Hassan Khosravi.
Copyright © 2004 Pearson Education, Inc.. Chapter 25 Distributed Databases and Client–Server Architectures.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
1 Copyright © 2004, Oracle. All rights reserved. Introduction.
1 ICS 184: Introduction to Data Management Lecture Note 11: Assertions, Triggers, and Index.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
1 SQL: Constraints and Triggers Chapter 5,
Triggers. Why Triggers ? Suppose a warehouse wishes to maintain a minimum inventory of each item. Number of items kept in items table Items(name, number,...)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Constraints and Triggers Chapter 5,
Chapter 6 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
Copyright © 2004 Pearson Education, Inc.. Chapter 21 Object Database Standards, Languages, and Design.
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the constraints.
Advanced SQL: Triggers & Assertions
1 Chapter 7 Triggers and Active Databases. 2 Trigger Overview Element of the database schema General form: ON IF THEN –Event- request to execute database.
1 Chapter 7 Triggers and Active Databases. 2 Trigger Overview Element of the database schema General form: ON IF THEN –Event- request to execute database.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
Advanced SQL Concepts - Checking of Constraints CIS 4301 Lecture Notes Lecture /6/2006.
1 SQL: Structured Query Language Chapter 5 (cont.)  Constraints  Triggers.
Chapter 9 Database Security and Authorization Copyright © 2004 Pearson Education, Inc.
Assertions and Triggers in SQL
ACTIVE DATABASE Traditional database systems are passive: respond to applications We may wish to extend the database systems by allowing them to invoke.
Database Management COP4540, SCS, FIU Database Trigger.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 Constraints and Triggers in SQL. 2 Constraints are conditions that must hold on all valid relation instances SQL2 provides a variety of techniques for.
Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.
Structured Query Language (3) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Active Database Concepts
Enhanced Data Models for Advanced Applications
7/4/2018.
7/5/2018.
Trigger Overview Element of the database schema
Advanced SQL: Views & Triggers
Triggers and Active Databases
Structured Query Language (3)
Assertions and Triggers
Presentation transcript:

Copyright © 2004 Pearson Education, Inc.

Chapter 24 Enhanced Data Models for Advanced Applications

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-3 Active Database Concepts and Triggers Generalized Model for Active Databases and Oracle Triggers Design and Implementation Issues for Active Databases Examples of Statement-Level Active Rules in STARBURST Potential Applications for Active Databases Triggers in SQL-99

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-4 Generalized Model for Active DB and Oracle Triggers Event-Condition-Action (ECA model) –Event : trigger the rule Usually database update –Condition : determines whether the rule action should be executed No condition – executed once the event occurs With condition – executed only when it is true –Action : usually a sequence of SQL statements

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-5 Generalized Model for Active DB and Oracle Triggers Example (fig. 24.1) –Assume that null is allowed for DNO –TOTAL_SAL is a derived attribute Events 1.Inserting new employee tuples 2.Changing the salary of existing employees 3.Changing the assignment of existing employees from one department to another 4.Deleting employee tuples

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-6 Generalized Model for Active DB and Oracle Triggers Condition –WHEN clause represents its condition DNO for new tuple is not null (1) An employee whose salary is changed is currently assigned to a department (2 and 4) No condition, always execute it (3) Action –Defined in PL/SQL block Automatically update TOTAL_SAL (1,2,& 4) Update TOTAL_SAL on the old department and later, the new department

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-7 Generalized Model for Active DB and Oracle Triggers CREATE TRIGGER : trigger name ruleevents AFTER : the rule will be triggered after the events occur ON : specifies the relation on which the rule is specified FOR EACH ROW : the rule will be triggered once for each row that is affected by event WHEN : specify any conditions checked after the rule is triggered but before the action is executed NEW and OLD

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-8 Generalized Model for Active DB and Oracle Triggers Examples R1, R2, R3, and R4 Row-level trigger vs. statement-level trigger –Row-level trigger Has FOR EACH ROW keyword The rule is triggered separately for each tuple –Statement-level trigger Doesn’t have FOR EACH ROW keyword The rule would be triggered once for each triggering statement

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 24-9 Generalized Model for Active DB and Oracle Triggers For example (statement-level trigger), –UPDATE EMPLOYEE SET SALARY = 1.1 * SALARY WHERE DNO = 5; Another example (See fig (b)) –To check whenever an employee’s salary is greater than the salary of his/her supervisor –We can call external procedure INFORM_SUPERVISOR, which notify the supervisor

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Design and Implementation Issues for Active Databases How rules are designed and implemented –In addition to creating rules, activate, deactivate, and drop rules are necessary. –Deactivated rule will not be triggered by the triggering event –The activate command will make the rule active again –The drop command deletes the rule from the system

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Design and Implementation Issues for Active Databases When triggered action should be executed –Before, after, or concurrently with the triggering event. Most commercial systems are limited to one or two of the options that we will now discuss

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Design and Implementation Issues for Active Databases Condition evaluation = rule consideration event condition Options for how the event is related to the evaluation of the rule’s condition 1.Immediate consideration : the condition is evaluated as part of the same transaction as the triggering event, and is evaluated immediately –Evaluate the condition before executing the triggering event –Evaluate the condition after executing the triggering event –Evaluate the condition instead of executing the triggering event 2.Deferred consideration : The condition is evaluated at the end of the transaction that included the triggering event. 3.Detached consideration : The condition is evaluated as a separate transaction, spawned from the triggering transaction

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Design and Implementation Issues for Active Databases conditionaction Options for the relationship between evaluating the rule condition and executing the rule action –Immediate, deferred, and detached Most active systems use the immediate option Oracle –uses the immediate consideration (with before/after option) and immediate execution model. –Row-level rules and statement-level rules STARBURST system uses the deferred consideration –Uses the deferred consideration –Only statement-level rules One of the difficulties that prevent the active rules being widespread is that there are no easy-to-use techniques for designing, writing, and verifying rules. (see fig.24.4)

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Examples of Statement-Level Active Rules in STARBURST STARBURST, IBM project, experimental DBMS In STARTBURST, only statement-level rules are allowed (see fig. 24.5) CREATE RULE : rule name ON : the relation on which the rule is specified WHEN : to specify the events IF : to specify any conditions (optional) THEN : to specify the action

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Examples of Statement-Level Active Rules in STARBURST Events : inserted, deleted, and updated INSERTED, DELETED, NEW- UPDATED, and OLD-UPDATED are used to refer to 4 transition tables that include –The newly inserted tuples, –The deleted tuples, –The updated tuples after they were updated, –And the updated tuples before they were updated, respectively

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Examples of Statement-Level Active Rules in STARBURST In statement-level semantics, since the rule designer only refer to the transition tables as a whole and the rule is triggered only once, so the rule must be different from the row-level semantics For example, because multiple employee tuples may be inserted in a single insert statement, we have to check if at least one of the newly inserted employee tuples is related to a department

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Examples of Statement-Level Active Rules in STARBURST In R1S (fig. 24.5) EXISTS (SELECT * FROM INSERTED WHERE DNO IS NOT NULL) WHEN (NEW.DNO IS NOT NULL) Examples in figure 24.5 STARBURST uses deferred consideration, which defer evaluation of condition and execution after the transaction ends

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Examples of Statement-Level Active Rules in STARBURST Example (fig. A)

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Potential Applications for Active Databases Potential applications of active rules –Notification Monitoring system –Enforce integrity constraints GPA alert and course prerequisites –Business rule Salary of employee can’t exceed that of manager –Maintenance of derived data Maintain the derived attribute TOTAL_SAL

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Triggers in SQL-99 Similar to Basic events : INSERT, DELETE, and UPDATE –UPDATE One may specify the attributes to be updated FOR EACH ROW and FOR EACH STATEMENT Can specify particular tuple variable names for the old and new tuples (fig. 24.6) Differences between row-level and statement- level trigger in REFERENCING clause

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Temporal Database Concepts Time Representation, Calendars, and Time Dimensions Incorporating Time in Relational Databases Using Tuple Versioning Incorporating Time in Object-Oriented Databases Using Attribute Versioning Temporal Querying Constructs and the TSQL2 Language Time Series Data

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Multimedia Databases Introduction to Spatial Database Concepts Introduction to Multimedia Database Concepts

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Introduction to Deductive Databases Overview of Deductive Databases Prolog/Datalog Notation Datalog Notation Clausal Form and Horn Clauses Interpretation of Rules Datalog Programs and Their Safety Use the Relational Operations Evaluation of Nonrecursive Datalog Queries

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide Summary