DATABASE VIEWS CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
SQL Constraints and Triggers
CREATE VIEW SYNTAX CREATE VIEW name [(view_col [, view_col …])] AS [WITH CHECK OPTION];
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
Cs3431 SQL: Updates (DML) and Views (DDL). cs3431 SQL DML (Updating the Data) Insert Delete Update.
Database Systems More SQL Database Design -- More SQL1.
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’
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
More SQL: Complex Queries, Triggers, Views, and Schema Modification 1.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Lecture # 11 July 12,2012 More SQL: Complex Queries, Triggers,
Onsdag The concepts in a relation data model SQL DDL DML.
Chapter 6 Database Administration
Using Special Operators (LIKE and IN)
Database Management COP4540, SCS, FIU Constraints and security in SQL (Ch. 8.6, Ch22.2)
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
Views Lesson 7.
NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Unit III. Views A table that is derived from other tables Considered as a virtual table Does not store data.
Announcements Written Homework 1 due Friday –If you have fourth edition make sure you do the right problems Program 3 out today, due next Friday Nov 10.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
1 Chapter 6 Database Administration. 2 Introduction Database administration The process of managing a database Database administrator A person or an entire.
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 8 Part 2 SQL-99 Schema Definition, Constraints, Queries, and Views.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
NULL VALUES CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1. LECTURE OUTLINE  Dealing with null values Three-valued logic Effects in WHERE clauses IS NULL Effects.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
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.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
1 VIEW Structured Query Language (SQL) - Part IV.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
A Guide to SQL, Sixth Edition 1 Chapter 5 Updating Data.
1 CS 430 Database Theory Winter 2005 Lecture 13: SQL DML - Modifying Data.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Chapter 7 SQL HUANG XUEHUA. Chapter Objectives Specification of more general constraints via assertions SQL facilities for defining views (virtual.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Structured Query Language (3) The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems,
More SQL: Complex Queries, Triggers, Views, and Schema Modification
More SQL: Complex Queries,
CS580 Advanced Database Topics
Views, Stored Procedures, Functions, and Triggers
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
SQL Views CS542.
SQL Views and Updates cs3431.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Structured Query Language (3)
SQL Views Presented by: Dr. Samir Tartir
Manipulating Data Lesson 3.
Presentation transcript:

DATABASE VIEWS CHAPTER 5 (6/E) CHAPTER 8 (5/E) 1

LECTURE OUTLINE  Database views provide convenient usage Virtual view realized when query uses that view  Materialized views allow efficient re-use Must be recalculated or updated when base tables change 2

VIEWS FOR CUSTOMIZATION  Consider database(s) describing university’s activities Academic institution Students, professors, classes Grades, transcripts Admissions, convocations Alumni Corporate institution Finances, human resources Board of Governors Capital assets Charitable institution Donors, fundraising activities Research institution Granting agencies, industrial/non-profits/academic partners Grants and contracts, intellectual property, licensing  Each user group provided appropriate “subset” of the data e.g., some financial/scheduling info relevant to most groups; other info confidential Underlying data shared, not silo’d.  Updates must be seen by all affected users. 3

VIEWS (VIRTUAL TABLES)  Consider again the query SELECT title, year, genre FROM Film WHERE director = 'Steven Spielberg' AND year > 1990; Returns all matching films currently in the database If re-run after updates, will give revised table of matches  A view is an unexecuted query that can be run on demand. Single table derived from other table(s) A virtual table 4

USING VIEWS IN SQL  CREATE VIEW command View name and a query to specify the contents of the view  Queries can use view as if it were a base table.  View always up-to-date (Re-)evaluated whenever a query uses the view Keeping it up-to-date is responsibility of the DBMS and not the user  DROP VIEW command Dispose of a view 5 CREATE VIEW Big_Earners AS SELECT E.Ssn AS Ssn, E.Lname AS Name, E.Salary AS Salary, M.Lname AS Manager FROM EMPLOYEE E, EMPLOYEE M WHERE E.Super_ssn = M.Ssn and E.Salary > M.Salary; SELECT * FROM Big_Earners WHERE Salary < ;

UPDATING A VIEW  What if an update is applied to a view as if it were a base table? Change corresponding tuple(s) in base table(s) Tuple might disappear from view! WITH CHECK OPTION clause at end of view definition ensures new and updated tuples match view definition (else error) Deleting tuple from view might require update to base table instead of deletion from base table e.g., deletion from CS338 view ≟ deletion from UW database? Not all views are updateable. What if Salary defined as sum of two base attributes or as aggregate such as SUM or AVG ? What if Big_Earners defined as a UNION of two tables? 6 CREATE VIEW Big_Earners AS SELECT E.Ssn AS Ssn, E.Lname AS Name, E.Salary AS Salary, M.Lname AS Manager FROM EMPLOYEE E, EMPLOYEE M WHERE E.Super_ssn = M.Ssn and E.Salary > M.Salary; UPDATE Big_Earners SET Salary = WHERE Name = 'Smith';

MATERIALIZED VIEWS  If the base tables don’t change, neither does the view instance. Re-executing view definition each time view is used is wasteful if base data has not been updated.  Solution: view materialization Create a temporary view table when the view is first queried Keep view table on the assumption that more queries using the view will follow Use materialized view (if it exists) to answer future query Requires efficient strategy for automatically updating view table when the base tables are updated Options when any base table is updated: 1.Delete the materialized view 2.Rematerialize the view 3.Incrementally update the view DBMS determines what new tuples must be inserted, deleted, or modified in materialized view 7

LECTURE SUMMARY  Views are virtual or derived tables.  Can be used for any query wherever base table can appear  May or may not be updatable Unions, joins, and (aggregate) functions are problematic  Materialized views used to save query time Must be kept up-to-date if base table(s) updated 8