Chapter 10 Views. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-2 Topics in this Chapter What are Views For? View Retrievals View Updates.

Slides:



Advertisements
Similar presentations
Views-basics 1. 2 Introduction a view is a perspective of the database different users may need to see the database differently; this is achieved through.
Advertisements

Data manipulation operations on views 1. 2 Outline retrieval operations in theory in practice (SQL92 and PostgreSQL) update operations in theory - basics.
1 Term 2, 2004, Lecture 6, Views and SecurityMarian Ursu, Department of Computing, Goldsmiths College Views and Security 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
1 Constraints, Triggers and Active Databases Chapter 9.
Database Administration, Integrity and Performance.
Chapter 3 An Introduction to Relational Databases.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
Chapter 3 An Introduction to Relational Databases.
Database Systems More SQL Database Design -- More SQL1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
With Microsoft Access 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Objectives of the Lecture :
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
CSC271 Database Systems Lecture # 6. Summary: Previous Lecture  Relational model terminology  Mathematical relations  Database relations  Properties.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Retrievals & Projections Objectives of the Lecture : To consider retrieval actions from a DB; To consider using relational algebra for defining relations;
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
Chapter 3 An Introduction to Relational Databases.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
Chapter 13 Further Normalization II: Higher Normal Forms.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
1 Context “Updating Union, Intersection and Difference views” - introduces a systematic approach to updating a view formed specifically by using  Union.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Unit III. Views A table that is derived from other tables Considered as a virtual table Does not store data.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Chapter 5 Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.5-2 Topics in this Chapter Values vs. Variables Types vs. Representations.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 3 The Relational Database Model.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 3 An Introduction to Relational Databases.
Chapter 4 An Introduction to SQL. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.4-2 Topics in this Chapter SQL: History and Overview The.
Chapter 2 The Big Picture. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2 Databases We are particularly interested in relational databases.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 4 An Introduction to SQL.
More SQL: Complex Queries,
Chapter 5 Database Design
Chapter 10 Views.
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
Lecture 2 The Relational Model
Methodology – Physical Database Design for Relational Databases
Chapter 4 Relational Databases
STRUCTURE OF PRESENTATION :
Chapter 3 The Relational Database Model
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Session #, Speaker Name Views 1/2/2019.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Presentation transcript:

Chapter 10 Views

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-2 Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-3 Views A view is created by applying an expression of relational algebra to a base relvar A view is a derived or virtual relvar Updates applied to the base relvar are immediately visible to the view Updates to values in the view “really” only update the base relvar by reiterating the original algebraic expression

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-4 What are Views For? A view can make subsequent queries much simpler (analogous to a macro) Views allow the same data to be seen by different users in different ways at the same time Views provide automatic security for hidden data Views can promote logical data independence

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-5 Logical Data Indendence Logical data independence means the immunity of users and user programs to changes in the logical structure of the database Growth aspect: New attributes or relvars can be added without affecting existing user programs Restructuring aspect: If a base relvar is split, the “old” structure can be emulated by a view; the “old” programs can now access the view

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-6 Base Relvars and Views The Principle of Interchangeability (of Base and Derived Relvars): There are no arbitrary and unnecessary distinctions between base and derived relvars The Principle of Database Relativity: From a user’s point of view, base relvars and views are logically equivalent

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-7 View Retrievals A relational expression is a relation-valued function It takes in relation(s) as arguments, and returns a relation A view is created using a relational expression, in which the relation returned is the view

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-8 View Updates A view is a relvar, and so is updateable by definition Earlier discussions of view updates tended to limit them It is in principle not necessary to limit them, apart from constraint enforcement View updates must adhere to the Golden Rule: no relvar must ever be allowed to violate its own predicate

Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-9 A View Updating Mechanism View updates must apply to appropriate underlying persistent relvars INSERT and DELETE should be inverses of each other UPDATE can be treated as a DELETE and an INSERT, so long as no intermediate actions or checks permitted View updates should be compatible with all relational operators

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – UNION Let view UV be defined as follows: VAR UV VIEW ( S WHERE STATUS > 25 ) UNION ( S WHERE CITY = ‘Paris’ ) ; Insert the following tuple into the view: ( S6, Smith, 50, Rome) This will insert the tuple into the suppliers base relvar, and thus appear in the view Similar effect for DELETE and UPDATE

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – INTERSECT If both sides of the intersect evaluate to true, the operation applies to the base relvars successfully Analogous to the effect in the case of a Union, except that both conditions must be satisfied For example, the status must be > 25, and the city must be Paris

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Difference A MINUS B The predicate is (PA) AND NOT (PB); The new tuple must satisfy PA, and not PB, and if so, it is inserted into A, or deleted from it, depending on which is invoked On an update the result must satisfy PA and not PB, and then the old version is deleted from A, and the updated version is inserted into A

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Restrict A where p, with a predicate of PA The predicate for V is (PA) AND p If the new tuple is presented to the view based on the RESTRICT, and it satisfies PA and p, it is inserted, deleted, or updated, as appropriate

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Project Let the attributes of A, with predicate PA, be partitioned into two disjoint groups, X and Y Consider X and Y as single composite attributes For INSERT, Y must have an acceptable default value to be used when X is satisfied (or vice versa) For DELETE, all tuples satisfied by X are deleted, regardless of the value of Y For UPDATE, prior Y values are retained

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Join To update a tuple of a view based on a join, it may be necessary to affect other tuples to preserve the view’s predicate Earlier writers concluded that it was impermissible to update such views Mr. Date believes a better approach is to follow through the ancillary implications, rather than to avoid such updates Joins can be one to one, one to many, or many to many

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Join Let J = A JOIN B, where A, B, and J have headings {X,Y}, {Y,Z} AND {X,Y,Z} The predicates are PA, PB, PJ, where PJ for J is PA (a) AND PB (b), where a is the A portion and b is the B portion For INSERT, the new tuple j must satisfy PJ. If the A portion of j does not appear in A, it is inserted, and likewise for the B portion in B Similar for DELETE and UPDATE

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Join – One to One A one to one join is more accurately called (zero-or-one) to (zero-or-one) For example, a separate supplier relvar whose only other attribute is favorite restaurant, and not all suppliers have one The view that joins supplier to suprest can permit inserts, deletes and updates that affect the underlying relvars in appropriate ways

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Join – One to Many A one to many join is more accurately called (zero-or-one) to (zero-or-more) Operations on the view will affect the underlying relvars appropriately A tuple inserted into such a view will insert a tuple into the underlying relvar on the one side, as well as a tuple into the underlying relvar on the many side DELETE will occur based on constraints on underlying relvars

Copyright © 2004 Pearson Addison-Wesley. All rights reserved A View Updating Mechanism – Join – Many to Many A many to many join is more accurately called (zero-or-more) to (zero-or-more) Operations on the view will affect the underlying relvars appropriately A tuple inserted into such a view will insert a tuple into the underlying relvars DELETE will occur based on constraints on underlying relvars Base relvars and views retain their predicates

Copyright © 2004 Pearson Addison-Wesley. All rights reserved Snapshots Snapshots are derived relvars, but they are not views Snapshots are the result of a relational operation that generates a read only relvar that is refreshed periodically An important case of controlled redundancy, used often for point in time reporting Snapshots have come to be misnamed “materialized views,” an oxymoron

Copyright © 2004 Pearson Addison-Wesley. All rights reserved SQL Facilities CREATE VIEW AS [WITH [ ] CHECK OPTION ] ; WITH CHECK OPTION is used for INSERTs and SELECTs: will make them fail if integrity constraints are violated; the default is that they will succeed regardless Can only be used with updateable views, as defined in SQL, which is narrower

Copyright © 2004 Pearson Addison-Wesley. All rights reserved SQL Facilities – Updateable Views in SQL The standard is more complex than any implementation of it; simplified, we say: Views defined as a restriction and/or projection of a single base table Views defined as a one to one join The many side of a one to many join UNION ALL or INTERSECT Other restrictions may apply