Chapter 10 Application Development with Views. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Creating.

Slides:



Advertisements
Similar presentations
Query Formulation with SQL
Advertisements

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.
12 CHAPTER DATABASES Databases are the key to accessing information throughout our lives. Used in hospitals, grocery stores, schools, department stores,
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Advanced Query Formulation with SQL.
Relational Model Stores data as tables –Each column contains values about the same attribute –Each column has a distinct name –Each row contains values.
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.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
3 / 12 CHAPTER Databases MIS105 Irfan Ahmed Ilyas.
7-1 Normalization - Outline  Modification anomalies  Functional dependencies  Major normal forms  Practical concerns.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Chapter 9 Advanced Query Formulation with SQL. Outline Outer join problems Type I nested queries Type II nested queries and difference problems Nested.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 9 Supplemental Slides Type II Nested Query Demonstration.
Chapter 6 Developing Data Models for Business Databases.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
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.
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 4 – Creating New.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
McGraw-Hill/Irwin The O’Leary Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Access 2002 Lab 4 Working with Multiple Tables.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
IE 423 – Design of Decision Support Systems Database development – Relationships and Queries.
ITBIS373 Database Development
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.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 9 – Building Links,
Chapter 12 View Design and Integration. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for view design.
McGraw-Hill/Irwin The O’Leary Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Access 2002 Lab 5 Creating Custom Forms.
1 Client/Server Databases and the Oracle Relational Database.
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.
Enhanced Guide to Oracle8i
Chapter 3 Query Formulation with SQL. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Getting started.
Chapter 9 View Design and Integration. © 2001 The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Outline Motivation for view design.
Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael V. Mannino All rights reserved. Chapter 6 Developing.
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).
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
McGraw-Hill/Irwin The O’Leary Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Access 2002 Lab 3 Analyzing Tables and Creating.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 4 Query Formulation with SQL.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL – Simple Queries and JOIN MGMT 360 Database Management.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
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.
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.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
1 Welcome to the World of Databases! Database technology: crucial to the operation and management of modern organisations Major transformation in computing.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 10 Application Development with Views.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Chapter 3: Relational Databases
Howard Paul. Sequential Access Index Files and Data File Random Access.
Chapter 3 Query Formulation with SQL. Outline Background Getting started Joining tables Summarizing tables Reasoning tools Advanced problems Data manipulation.
Slide 1Chapter 9: Advanced Query Formulation with SQL Database Design, Application Development, and Administration, 5 th Edition Copyright © 2011 by Michael.
7 Copyright © 2006, Oracle. All rights reserved. Normalization of Relational Tables (Part II)
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
Developing Data Models – Conversion Rules
Query Formulation with SQL
SQL 101.
* 07/16/96 Normalization 2/16/2019 *.
Chapter 3 Supplemental Slides
Presentation transcript:

Chapter 10 Application Development with Views

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Background Creating views and using views Processing queries that reference views Updatable views Data requirements for hierarchical forms Data requirements for reports

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

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. 1-M Updatable Queries Associated with 1-M relationships Join column of the parent table: primary key or unique Determine updatable tables Child table updatable –Primary key –Foreign key: must include in the query result –Required columns of the child table Include primary key and required columns to support insert operations on the parent table Use join operator style

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. 1-M Updatable Query Example Example 10: Save as Course_Offering_View1 SELECT Course.CourseNo, CrsDesc, CrsUnits, Offering.OfferNo, OffTerm, OffYear, Offering.CourseNo, OffLocation, OffTime, FacSSN, OffDays FROM Course INNER JOIN Offering ON Course.CourseNo = Offering.CourseNo

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Usage of a 1-M Updatable Query Example 11: Insert a row into the Course_Offering_View1. INSERT INTO Course_Offering_View1 ( OfferNo, Offering.CourseNo, OffTerm, OffYear, OffLocation, OffTime, FacSSN, OffDays ) VALUES ( 7799, 'IS480', 'Spring', 2003, 'BLM201', #1:30PM#, ' ', 'MW' )

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Extensions to Multiple Tables Apply rules to each 1-M relationship FK of each child table in the query result Usually only the lowest level child table is updatable Examples –Course-Offering, Faculty-Offering –Offering-Enrollment, Faculty-Offering

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Hierarchical Forms Formatted window for data entry and display Main form Subform Provide attractive interface for a 1-M relationship Specification of data requirements is important

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Revised University Database

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Example Hierarchical Form

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Analysis of Data Requirements Identify the 1-M relationship Identify the linking fields Determine other tables in the main form and the subform Determine updatable tables Write queries for the main form and subform

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Data Requirements for the Registration Form 1-M relationship: Registration-Enrollment Linking fields: Registration.RegNo, Enrollment.RegNo Other tables –Main form: Student –Subform: Offering, Course, Faculty Updatable tables: Registration, Enrollment

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Registration Main Form Query SELECT RegNo, RegTerm, RegYear, RegDate, Registration.StdSSN, Registration.StdSSN, RegStatus, StdFirstName, StdLastName, StdClass, StdCity, StdState FROM Registration INNER JOIN Student ON Registration.StdSSN = Student.StdSSN

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Registration Subform Query SELECT RegNo, Enrollment.OfferNo, OffTime, Offering.CourseNo, OffLocation, OffTerm, OffYear, Offering.FacSSN, FacFirstName, FacLastName, CrsDesc, CrsUnits FROM ( ( Enrollment INNER JOIN Offering ON Enrollment.OfferNo = Offering.OfferNo ) INNER JOIN Course ON Offering.CourseNo = Course.CourseNo ) LEFT JOIN Faculty ON Faculty.FacSSN = Offering.FacSSN

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Faculty Assignment Form

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Data Requirements for the Faculty Assignment Form Step 1: Faculty (parent table), Offering (child table) Step 2: Faculty.FacSSN, Offering.FacSSN Step 3: Course table in the subform Step 4: update Offering.FacSSN

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Faculty Assignment Queries Main form SELECT FacSSN, FacFirstName, FacLastName, FacDept FROM Faculty Subform SELECT OfferNo, Offering.CourseNo, FacSSN, OffTime, OffDays, OffLocation, CrsUnits FROM Offering INNER JOIN COURSE ON Offering.CourseNo = Course.CourseNo

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Hierarchical Reports Stylized presentation of data appropriate to a selected audience Use nesting (or indentation) to provide a visually appealing layout Vocabulary –Group: sorted field; usually indented –Detail line: innermost field

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Example Hierarchical Report

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Summary Data in Detail Lines

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Query Formulation Skills for Reports Less difficult than skills for forms Inspect report –Match fields in the report to database columns –Determine the needed tables –Identify the join conditions Determine the level of detail –Row data versus summary data –Query should provide data for the detail lines

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Faculty Work Load Query SELECT Offering.OfferNo, FacFirstName, FacLastName, FacDept, OffTerm, CrsUnits, OffLimit, Count(Enrollment.RegNo) AS NumStds, NumStds/Offlimit AS PercentFull, (NumStds/Offlimit) < 0.25 AS LowEnrollment FROM Faculty, Offering, Course, Enrollment WHERE Faculty.FacSSN = Offering.FacSSN AND Course.CourseNo = Offering.CourseNo AND Offering.OfferNo = Enrollment.OfferNo AND ( ( Offering.OffTerm = 'Fall' AND Offering.OffYear = 2002 ) OR ( Offering.OffTerm = 'Winter' AND Offering.OffYear = 2003 ) OR ( Offering.OffTerm = 'Spring' AND Offering.OffYear = 2003 ) ) GROUP BY Offering.OfferNo, FacFirstName, FacLastName, FacDept, OffTerm, CrsUnits, OffLimit

McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Summary Significant benefits with a modest performance penalty Foundation of application data requirements Updatable views important for hierarchical forms Carefully analyze data requirements before developing forms and reports