Views 1.

Slides:



Advertisements
Similar presentations
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
Advertisements

Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 Lecture 11: Basic SQL, Integrity constraints
SQL Part II: Advanced Queries. 421B: Database Systems - SQL Queries II 2 Aggregation q Significant extension of relational algebra q “Count the number.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Views. 2 What are views good for?(1) Simplifying complex queries: we saw one example. Here is another example that allows the user to "pretend" that.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
1 Views. 2 What are views good for? (1) Simplifying complex queries: We saw one example. Here is another that allows the user to "pretend" that there.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
1 The Relational Model Chapter 3. 2 Objectives  Representing data using the relational model.  Expressing integrity constraints on data.  Creating,
The Relational Model These slides are based on the slides of your text book.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Database Management Systems, 2 nd Edition. R. Ramakrishnan and J. Gehrke1 Data Warehousing and Decision Support Chapter 25, Part B.
1 The Relational Model Chapter 3. 2 Why Study the Relational Model?  Most widely used model  Vendors: IBM, Informix, Microsoft, Oracle, Sybase  Recent.
More on Views (3.6—3.7) Author: Dr. Adam Anthony For text: Database Management Systems (Ramakrishnan and Gherke)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
ICS 321 Fall 2011 Constraints, Triggers, Views & Indexes Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa.
The Relational Model1 ER-to-Relational Mapping and Views.
Views Lesson 7.
ICS 321 Fall 2009 The Relational Model (ii) Asst. Prof. Lipyeow Lim Information and Computer Science Department University of Hawaii at Manoa 9/10/20091Lipyeow.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Relational Model Content based on Chapter 3 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #5 (E-R  Relational, Cont.) Instructor: Chen Li.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
IST 210 Security. IST 210 Introduction to DB Security Secrecy: Users should not be able to see things they are not supposed to. E.g., A student can’t.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL Query Getting to the data ……..
COP Introduction to Database Structures
CS 186, Fall 2006, Lecture 2 R & G, Chap. 3
Chapter 4 Relational Databases
Lecture#7: Fun with SQL (Part 2)
Database Applications (15-415) The Relational Model Lecture 4, January 16, 2018 Mohammad Hammoud.
The Relational Model Content based on Chapter 3
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
SQL Views and Updates cs3431.
Databases.
The Relational Model Transparencies
Data Warehousing and Decision Support
Unit I-2.
SQL: Structured Query Language
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Structured Query Language (3)
Database Design: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
SQL-Views and External Schemas
SQL Views Presented by: Dr. Samir Tartir
The Relational Model Content based on Chapter 3
The Relational Model Content based on Chapter 3
Views Base Relation View
Presentation transcript:

Views 1

Views A view is just a relation, but we store a definition, rather than a set of tuples. CREATE VIEW YoungActiveStudents (name, grade) AS SELECT S.name, E.grade FROM Students S, Enrolled E WHERE S.sid = E.sid and S.age<21 Views can be dropped using the DROP VIEW command. How to handle DROP TABLE if there’s a view on the table? DROP TABLE command has options to let the user specify this. 18

Uses for Views Views can be used to present necessary information (or a summary), while hiding details in underlying relation(s) (security). Views also useful for maintaining logical data independence when the conceptual schema changes. Can be used to precompute (materialize) results or partial results of common queries. 22

Views vs. Relations Logical distinctions: Physical distinctions: Updates not always possible to a view Physical distinctions: Relations must be physically stored somewhere Views are either: Computed on-demand (not indexable) Stored physically (materialized) to enhance performance, and the DBA (or system) must manage the replication.

Processing Queries with Views For logically stored views, use query modification: Could be rewritten (modified): or: SELECT Y.* FROM YoungActiveStudents Y WHERE Y.name = ‘Sam’ SELECT Y.* FROM ( <view definition goes here> ) AS Y WHERE Y.name = ‘Sam’ SELECT S.name, E.grade FROM Students S, Enrolled E WHERE S.sid = E.sid and S.age < 21 and S.name = ‘Sam’

Processing Queries with Views (cont.) For materialized views, updates to view data to maintain integrity can be: Immediate: triggered by each base relation update Deferred: allows temporary inconsistency in DB: Lazy: Refresh views only as needed by queries Faster updates Slower queries Periodic: Refresh views every n seconds (called snapshots) Forced: Refresh views after every n updates to base tables Query is processed as if view were a physically stored relation.

Updates to Views Whether view is materialized or not, we can’t always update a view because there may not be a unique update to base tables that reflects the update to the view. Single-table views are usually updateable. Multi-table views are more difficult. We will consider views defined using union, intersect, minus, and join. Assumption: WITH CHECK OPTION in force

Updates to Single-Table Views Selection-based views: INSERT, DELETE are mapped directly to the base relation. Projection-based views: view must include all fields of base relation that disallow null; base table insertion is padded with nulls. Aggregate views: not updateable. CREATE VIEW YearAvg AS SELECT S.year, AVG (S.gpa) FROM Students S GROUP BY S.year

Updates to Multi-Table Views A UNION B: Inserted tuple goes into A if it satisfies A’s definition and into B if it satisfies B’s definition (A, B can be views or base tables; at least one must be satisfied) Deleted tuples deleted from both A and B Update = atomic (delete, insert) sequence Example: RichEmps UNION SeattleEmps = RichSeattleEmps

Updates to Multi-Table Views A INTERSECT B: Inserted tuple goes into both A and B, assuming it satisfies definitions of both Deleted tuple deleted from both A and B A MINUS B: Inserted tuple goes into A, assuming it satisfies definition of A and doesn’t satisfy B Deleted tuple is deleted from A

Updates to Multi-Table Views A JOIN B: Inserted tuple: A-portion inserted into A and B-portion inserted into B (if possible) NOTE: May “generate” new tuples for view this way!!! Deleted tuple: A-portion deleted from A and B-portion deleted from B

Reality … Those rules are as liberal as possible. Most actual systems require the following of a view definition for it to be updateable: No GROUP, DISTINCT, UNION, MINUS, INTERSECT, or arithmetic Update must be resolvable to specific rows in exactly one of the base tables involved in the view. For deletion, only single-table views are updateable.

Summary Views useful for security, logical data independence, performance Stored logically (query modification required) or physically (materialized) View updates must be unambiguously mappable to base relation updates in order to be allowed. Most systems don’t allow as many view updates as they could

State of the Art (views) Views are becoming important for processing “decision support” queries Automated view creation and management (based on evolving workload) View and trigger interactions (semantics, optimization) Views for answering aggregation queries (query modification algorithms, etc.) Views to integrate multiple data sources Algorithms for deferred view maintenance