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.

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.
February 18, 2012 Lesson 3 Standard SQL. Lesson 3 Standard SQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Database Languages Chapter 7. The Relational Algebra.
Unit 5 The Network Model  5.1 The Network Model  5.2 IDMS.
Database Administration, Integrity and Performance.
Chapter 3 An Introduction to Relational Databases.
Wei-Pang Yang, Information Management, NDHU More on Normalization Unit 18 More on Normalization ( 表格正規化探討 ) 18-1.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Domains, Relations & Base RelVars (Ch
Database Systems More SQL Database Design -- More SQL1.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
Database Systems Lecture # 8 11 th Feb,2011. The Relational Model of Data The term relation is basically just a mathematical term for a table. DBMS products.
Data Manipulation 11 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and other programming.
Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
6.8 Case Study: E-R for Supplier-and-Parts Database
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
The Relational Model Part III. Remember: 3 Aspects of the Model It concerns 1) data objects storing it 2) data integrity making sure it corresponds to.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
1 Structured Query Language (SQL) CIS*2450 Advanced Programming Concepts.
Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )
Further Normalization II: Higher Normal Forms Prof. Yin-Fu Huang CSIE, NYUST Chapter 13.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
An Introduction to Relational Databases Prof. Yin-Fu Huang CSIE, NYUST Chapter 3.
Further Normalization I
Data Definition After this lecture, you should be able to:
An Introduction to SQL Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
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:
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Unit 5 The Network Model  5.1 Data Modeling Issues  5.2 The Network Model  5.3 IDMS.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
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.
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
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.
Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
Relational Algebra Prof. Yin-Fu Huang CSIE, NYUST Chapter 7.
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.
Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.
Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary.
Unit 2 DB2 and SQL. 2-2 Wei-Pang Yang, Information Management, NDHU Outline of Unit Overview 2.2 Data Definition 2.3 Data Manipulation 2.4 The System.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Advanced Database System
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.
Structured Query Language IV Asma Ahmad (C. J. Date) Database Systems.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 4 An Introduction to SQL.
STRUCTURE OF PRESENTATION :
Chapter 10 Views.
Unit 2 DB2 and SQL.
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
Chapter 8 Relational Calculus.
پايگاه داده ها.
Φροντιστήριο SQL (από το βιβλίο του Date)
Advanced Database System
Unit 7 Normalization (表格正規化).
STRUCTURE OF PRESENTATION :
Question 1: Basic Concepts (45 %)
STRUCTURE OF PRESENTATION :
Presentation transcript:

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 > 15) {S#, Status, City}; (See Fig. 10.1) The view-defining expression is not evaluated but is merely “remembered” by the system. a derived and virtual relvar A window into the underlying data

Advanced Database System Yin-Fu Huang 10.1Introduction (Cont.)  Example: Good_Supplier Where City ≠ ‘London’ (S Where Status > 15 And City ≠ ‘London’) { S#, Status, City } Any updates: view the underlying data Further Examples  Exam 1: Var Redpart View ((P Where Color=Color(‘Red’)){All But Color}) Rename Weight As Wt;  Exam 2: Var Pq View Summarize Sp Per P {P#} Add Sum (Qty) As Totqty;  Exam 3: Var City_Pair View ((S Rename City As Scity) Join Sp Join (P Rename City As Pcity)) {Scity, Pcity};  Exam 4: Var Heavy_Redpart View Redpart Where Wt > Weight(12.0);

Advanced Database System Yin-Fu Huang 10.1Introduction (Cont.) Defining and Droping Views Var View ; Drop Var ;

Advanced Database System Yin-Fu Huang 10.2What Are Views for? Reasons: 1. Views provide a shorthand or “macro” capability. 2. Views allow the same data to be seen by different users in different ways at the same time. 3. Views provide automatic security for hidden data. 4. Views can provide logical data independence. Logical Data Independence  The immunity of users and user programs to changes in the logical structure of the database.  Growth  New attributes  New base relvar

Advanced Database System Yin-Fu Huang 10.2What Are Views for? (Cont.)  Restructuring e.g., Var Snc Base Relation {S# S#, Sname Name, City Char} Primary Key {S#}; Var St Base Relation {S# S#, Status Integer} Primary Key {S#}; Var S View Snc Join St;  Information-equivalent Two Important Principles  The Principle of Interchangeability  The Principle of Database Relativity

Advanced Database System Yin-Fu Huang View Retrievals V = X(D) RO(V) = RO(X(D)) View Updates (1/12) Given a particular update on a particular view, what updates need to be applied to what underlying base relvars in order to implement the original view update? V = X(D) UO(V) = UO(X(D)) = X(UO’(D)) The Golden Rule Revisited No update operation must ever assign to any relvar a value that causes its relvar predicate to evaluate to False.

Advanced Database System Yin-Fu Huang View Updates (2/12) Union: A Union B (PA) Or (PB) e.g., Var UV View (S Where Status > 25) Union (S Where City = ‘Paris’); (See Fig. 10.2)

Advanced Database System Yin-Fu Huang View Updates (3/12)  Insert (S6, Smith, 50, Rome) (S7, Jones, 50, Paris) Suppose SA and SB are two distinct base relvars. (See Fig. 10.3) (S6, Smith, 50, Rome) insert into only SA (S7, Jones, 50, Paris) insert into SA and SB

Advanced Database System Yin-Fu Huang View Updates (4/12)  Delete  Update a Delete-Insert sequence Intersect: A Intersect B (PA) And (PB) Difference: A Minus B (PA) And Not (PB) Restrict: A Where p (PA) And (p) e.g., Var LS View S Where City = ‘London’; (See Fig. 10.4)

Advanced Database System Yin-Fu Huang View Updates (5/12)  Insert (S6, Green, 20, London) (S1, Green, 20, London) fail (S6, Green, 20, Athens) fail  Delete (S1, Smith, 20, London)  Update (S1, Smith, 20, London) (S6, Green, 20, London) (S1, Smith, 20, London) (S2, Smith, 20, London) fail (S1, Smith, 20, London) (S1, Smith, 20, Athens) fail

Advanced Database System Yin-Fu Huang View Updates (6/12) Project: A{X} A{X} e.g., Var SC View S {S#, City}; (See Fig. 10.5)  Insert (S6, Athens) (S1, Athens) fail  Delete (S1, London)  Update (S1, London) (S1, Athens) (S1, London) (S2, London) fail

Advanced Database System Yin-Fu Huang View Updates (7/12) Extend: Extend A Add exp As X PA(a) And e.X = exp (a) e.g., Var VPX View Extend P Add (Weight*454) As Gmwt; (See Fig. 10.6)

Advanced Database System Yin-Fu Huang View Updates (8/12)  Insert (P7, Cog, Red, 12, Paris, 5448) (P7, Cog, Red, 12, Paris, 5449) fail (P1, Cog, Red, 12, Paris, 5448) fail  Delete (P1, Nut, Red, 12, London, 5448)  Update (P1, Nut, Red, 12, London, 5448) (P1, Nut, Red, 10, Paris, 4540) (P1, Nut, Red, 12, London, 5448) (P2, Nut, Red, 12, London, 5448) fail

Advanced Database System Yin-Fu Huang View Updates (9/12) Join: A Join B PA(a) And PB(b)  Case 1 (one-to-one) e.g., S Join SR;  Case 2 (one-to-many) e.g., Var SSP View S Join SP; (See Fig. 10.7)

Advanced Database System Yin-Fu Huang View Updates (10/12) Insert (S4, Clark, 20, London, P6, 100) (S5, Adams, 30, Athens, P6, 100) (S6, Green, 20, London, P6, 100) (S4, Clark, 20, Athens, P6, 100) fail (S1, Smith, 20, London, P1, 400) fail Delete (S3, Blake, 30, Paris, P2, 200) (S1, Smith, 20, London, P1, 300) No Action or Restrict, fail Cascade, deleting all other SP tuples for S1 Update (S1, Smith, 20, London, P1, 300) (S1, Smith, 20, London, P1, 400) (S1, Smith, 20, London, P1, 300) (S1, Smith, 20, Athens, P1, 400) (S1, Smith, 20, London, P1, 300) (S6, Smith, 20, London, P1, 300) Update rule from SP to S

Advanced Database System Yin-Fu Huang View Updates (11/12)  Case 3 (many-to-many) e.g., Var S-P View S Join P; (See Fig. 10.8)

Advanced Database System Yin-Fu Huang View Updates (12/12)  Insert (S1, Smith, 20, London, P7, Washer, Red, 5) adding two tuples to the view (S6, Green, 20, London, P7, Washer, Red, 5) adding six tuples to the view  Delete (S1, Smith, 20, London, P1, Nut, Red, 12) deleting four tuples from the view Other Operators  Summarize e.g., Summarize SP Per SP {S#} Add Sum (Qty) As Totqty; Update (S4, 900) (S4, 800) fail Insert (S5, 0) fail

Advanced Database System Yin-Fu Huang Snapshots (A Digression) Like views, snapshots are derived relvars; unlike views, however, they are real, not virtual. e.g., Var P2SC Snapshot ((S Join SP) Where P#=P#(‘P2’)) {S#, City} Refresh Every Day;

Advanced Database System Yin-Fu Huang SQL Facilities Create View As [With [ ] Check Option]; e.g., Create View Good_Supplier As Select S.S#, S.Status, S.City From S Where S.Status > 15 With Check Option; Drop View ;

Advanced Database System Yin-Fu Huang SQL Facilities (Cont.) SQL’s support for view updating is limited. Loosely speaking, we can say that SQL regards the following views as updatable:  Views defined as a restriction and/or projection of a single base table  Views defined as a one-to-one or one-to-many join of two base tables (in the one-to-many case, only the ‘many’ side is updatable)  Views defined as a UNION ALL or INTERSECT of two distinct base tables  Certain combinations of Cases 1-3

Advanced Database System Yin-Fu Huang The End.