McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. What is a View? Derived table Behaves like a base table (virtual) Stored.

Slides:



Advertisements
Similar presentations
Query Formulation with SQL
Advertisements

© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Project Analysis and Evaluation Chapter Eleven.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Credit and Inventory Management Chapter Twenty-One.
Chapter 8 Normalization. © 2001 The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Outline Modification anomalies Functional dependencies.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Working with Financial Statements Chapter Three.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Advanced Query Formulation with SQL.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Raising Capital Chapter Sixteen.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Options and Corporate Finance Chapter Fourteen.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Introduction to Valuation: The Time Value of Money Chapter Five.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Developing Data Models for Business Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 7 Normalization of Relational Tables.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Net Present Value and Other Investment Criteria Chapter Nine.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Short-Term Finance and Planning Chapter Nineteen.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Determining the Target Cash Balance Chapter Twenty A.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Long-Term Financial Planning and Growth Chapter Four.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Interest Rates and Bond Valuation Chapter Seven.
3 / 12 CHAPTER Databases MIS105 Irfan Ahmed Ilyas.
7-1 Normalization - Outline  Modification anomalies  Functional dependencies  Major normal forms  Practical concerns.
Chapter 9 Advanced Query Formulation with SQL. Outline Outer join problems Type I nested queries Type II nested queries and difference problems Nested.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Option Valuation Chapter Twenty- Four.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Supplemental Slides Type II Nested Query Demonstration.
© 2003 The McGraw-Hill Companies, Inc. All rights reserved. Return, Risk, and the Security Market Line Chapter Thirteen.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 3 The Relational Data Model.
SQL - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Chapter 4 The Relational Model Pearson Education © 2014.
Chapter 7 Normalization. Outline Modification anomalies Functional dependencies Major normal forms Relationship independence Practical concerns.
Chapter 7 Normalization. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Modification anomalies Functional dependencies.
Copyright © 2011 by Michael V. Mannino All rights reserved. Database Design, Application Development, and Administration, 5 th Edition Chapter 3 The Relational.
Chapter 2 The Relational Data Model. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Relational model basics Integrity.
Chapter 14 Data and Database Administration. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Organizational context.
Instructor: Dema Alorini Database Fundamentals IS 422 Section: 7|1.
Chapter 10 Application Development with Views. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Creating.
Chapter 3 Query Formulation with SQL. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Getting started.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Advanced Query Formulation with SQL. 9-2 Outline  Outer join problems  Type I nested queries  Type II nested queries and difference problems  Nested.
Chapter 9 Advanced Query Formulation with SQL. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Outer join problems.
9 Advanced Query Formulation with SQL (Chapter 9).
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 4 Query Formulation with SQL.
SQL – Simple Queries and JOIN MGMT 360 Database Management.
Indexes and Views Unit 7.
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.
1 Welcome to the World of Databases! Database technology: crucial to the operation and management of modern organisations Major transformation in computing.
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,
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 10 Application Development with Views.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc., All Rights Reserved. Example 1-Ad A.
Chapter 3 Query Formulation with SQL. Outline Background Getting started Joining tables Summarizing tables Reasoning tools Advanced problems Data manipulation.
Chapter 4 The Relational Model Pearson Education © 2009.
Slide 1Chapter 9: Advanced Query Formulation with SQL Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Chapter 2 The Relational Data Model. Outline Relational model basics Integrity rules Rules about referenced rows Relational Algebra.
Application Development with Views
The Relational Data Model
Introduction to Database Management
Developing Data Models – Conversion Rules
Query Formulation with SQL
Views.
SQL 101.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 3 Supplemental Slides
Chapter 4 The Relational Model Pearson Education © 2009.
Views.
Views Base Relation View
Presentation transcript:

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. What is a View? Derived table Behaves like a base table (virtual) Stored query

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. View Advantages Reduce impact of database definition changes Simplify database usage Unit of database security Can be a performance penalty on complex views

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Three Schema Architecture

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. View Definition Example Example 1: Create a view consisting of offerings taught by faculty in the MS department. CREATE VIEW MS_View AS SELECT OfferNo, Course.CourseNo, CrsUnits, OffTerm, OffYear, Offering.FacSSN, FacFirstName, FacLastName, OffTime, OffDays FROM Faculty, Course, Offering WHERE FacDept = 'MS' AND Faculty.FacSSN = Offering.FacSSN AND Offering.CourseNo = Course.CourseNo

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Column Renaming Example 2: create a view containing offering data and the number of enrolled students. CREATE VIEW Enrollment_View ( OfferNo, CourseNo, Term, Year, Instructor, NumStudents ) AS SELECT Offering.OfferNo, CourseNo, OffTerm, OffYear, FacLastName, COUNT(*) FROM Offering, Faculty, Enrollment WHERE Offering.FacSSN = Faculty.FacSSN AND Offering.OfferNo = Enrollment.OfferNo GROUP BY Offering.OfferNo, CourseNo, OffTerm, OffYear, FacFirstName, FacLastName

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Using Views Example 3 SELECT OfferNo, CourseNo, FacFirstName, FacLastName, OffTime, OffDays FROM MS_View WHERE OffTerm = 'SPRING' AND OffYear = 2003 Example 4 SELECT OfferNo, Instructor, NumStudents, CrsUnits FROM Enrollment_View, Course WHERE Enrollment_View.CourseNo = Course.CourseNo AND NumStudents < 5

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Processing View Queries Materialization –Execute two queries –Large overhead –Preferred in static environments Modification –Substitute view definition for view references –Execute one query –Incurs little overhead –Not possible for all view queries

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Modification Example Example 5: Query using a view SELECT OfferNo, CourseNo, FacLastName FROM MS_View WHERE OffYear = 2003 Example 6: Modified query SELECT OfferNo, Course.CourseNo, FacLastName FROM Faculty, Course, Offering WHERE FacDept = 'MS' AND OffYear = 2003 AND Faculty.FacSSN = Offering.FacSSN AND Offering.CourseNo = Course.CourseNo

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Single Table Updatable Views Support modification statements Rules for single table updatable views –1-1 correspondence between view rows and base table rows –View includes PK of base table –View includes all required columns –View definition does not have GROUP BY or DISTINCT

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Updatable View Examples Example 7: Single table updatable view CREATE VIEW Fac_View1 AS SELECT FacSSN, FacFirstName, FacLastName, FacRank, FacSalary, FacDept, FacCity, FacState, FacZipCode FROM Faculty WHERE FacDept = 'MS' Example 8: View update UPDATE Fac_View1 SET FacSalary = FacSalary * 1.1 WHERE FacRank = 'ASST'

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. View Update with Side Effects Modify column used in the WHERE condition of a view definition Use WITH CHECK OPTION clause to prevent Example 9: Change the department of rows in the Fac_View1 UPDATE Fac_View1 SET FacDept = 'FIN' WHERE FacSalary >

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Multiple Table Updatable Views No industry standard Only recently supported More complex rules than single table updatable views Access supports flexible view updates for multi-table views Oracle rules in Appendix 10.B