VIEWS virtual relation data duplication consistency problems



Similar documents
Chapter 8. SQL-99: SchemaDefinition, Constraints, and Queries and Views

Lab Assignment Creating a Relational Database Schema from ER Diagram, Populating the Database and Querying over the database with SQL

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Relational Schema. CS 4700/6700 A Sample of Small Database Design Using Microsoft Access

CSC 443 Data Base Management Systems. Basic SQL

SQL Nested & Complex Queries. CS 377: Database Systems

Part 4: Database Language - SQL

Introduction to SQL: Data Retrieving

Summary on Chapter 4 Basic SQL

How To Create A Table In Sql (Ahem)

More SQL: Assertions, Views, and Programming Techniques

CS 338 Join, Aggregate and Group SQL Queries

New York University Computer Science Department Courant Institute of Mathematical Sciences

CHAPTER 8: SQL-99: SCHEMA DEFINITION, BASIC CONSTRAINTS, AND QUERIES

The Relational Algebra

Chapter 9, More SQL: Assertions, Views, and Programming Techniques

SQL-99: Schema Definition, Basic Constraints, and Queries

1 Structured Query Language: Again. 2 Joining Tables

Natural Language Interfaces (NLI s)

Using Temporary Tables to Improve Performance for SQL Data Services

3. Relational Model and Relational Algebra

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

Relational Algebra. Query Languages Review. Operators. Select (σ), Project (π), Union ( ), Difference (-), Join: Natural (*) and Theta ( )

Introduction to tuple calculus Tore Risch

b. Examine the following histories. Draw their serialization graph and identify which of them is serializable given reasons.

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

10CS54: DATABASE MANAGEMENT SYSTEM

SQL NULL s, Constraints, Triggers

ER & EER to Relational Mapping. Chapter 9 1

4. SQL. Contents. Example Database. CUSTOMERS(FName, LName, CAddress, Account) PRODUCTS(Prodname, Category) SUPPLIERS(SName, SAddress, Chain)

Lab Manual. Database Systems COT-313 & Database Management Systems Lab IT-216

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

There are five fields or columns, with names and types as shown above.

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)


CSCI315 Database Design and Implementation

Course Notes on Databases and Database Management Systems

Chapter 13: Query Optimization

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

Database Management Systems. Chapter 1

Principles of Database Management Systems. Overview. Principles of Data Layout. Topic for today. "Executive Summary": here.

Introduction to database management systems

Overview. Introduction to Database Systems. Motivation... Motivation: how do we store lots of data?

CHAPTER 3. Relational Database Management System: Oracle. 3.1 COMPANY Database

Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation

Physical DB design and tuning: outline

COURSE CODE: CIT 844 COURSE TITLE: ADVANCED DATABASE MANAGEMENT SYSTEM

SQL Tables, Keys, Views, Indexes

How To Use The Database In Jdbc.Com On A Microsoft Gdbdns.Com (Amd64) On A Pcode (Amd32) On An Ubuntu (Amd66) On Microsoft

Oracle Database 10g: Introduction to SQL

Scheme G. Sample Test Paper-I

Foundations of Information Management

Normalization in OODB Design

Basic Concepts of Database Systems

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

Databases and BigData

Relational Database: Additional Operations on Relations; SQL

featuring data privacy Andres Avelino Campos Sainz A Project submitted in partial fulfillment of the requirements for the degree of

Chapter 1: Introduction. Database Management System (DBMS)

Week 4 & 5: SQL. SQL as a Query Language

DBMS / Business Intelligence, SQL Server

Foundations of Information Management

Data Structure: Relational Model. Programming Interface: JDBC/ODBC. SQL Queries: The Basic From

CS143 Notes: Views & Authorization

!"#"$%&'(()!!!"#$%&'())*"&+%

MySQL for Beginners Ed 3

Exercise 1: Relational Model

SECURITY CHAPTER 24 (6/E) CHAPTER 23 (5/E)

UNIT 6. Structured Query Language (SQL) Text: Chapter 5

A basic create statement for a simple student table would look like the following.

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Migrating from Sybase to SQL Server

Database Theory, Fall Semester MMXV: Week #3

THE OPEN UNIVERSITY OF TANZANIA FACULTY OF SCIENCE TECHNOLOGY AND ENVIRONMENTAL STUDIES BACHELOR OF SIENCE IN INFORMATION AND COMMUNICATION TECHNOLOGY

SUBQUERIES AND VIEWS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 6

Mini User's Guide for SQL*Plus T. J. Teorey

Structured Query Language (SQL)

Figure 14.1 Simplified version of the

Advance DBMS. Structured Query Language (SQL)

Introduction to normalization. Introduction to normalization

Data Integration and Exchange. L. Libkin 1 Data Integration and Exchange

Chapter 5. SQL: Queries, Constraints, Triggers

Before you may use any database in Limnor, you need to create a database connection for it. Select Project menu, select Databases:

Chapter 6: Physical Database Design and Performance. Database Development Process. Physical Design Process. Physical Database Design

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Database 2 Lecture I. Alessandro Artale

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Instant SQL Programming

Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008

Lecture 6. SQL, Logical DB Design

HTSQL is a comprehensive navigational query language for relational databases.

SQL Introduction Chapter 7, sections 1 & 4. Introduction to SQL. Introduction to SQL. Introduction to SQL

AN INTRODUCTION TO THE SQL PROCEDURE Chris Yindra, C. Y. Associates

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Avatier Identity Management Suite

Transcription:

VIEWS A virtual relation that is defined from other preexisting relations Called the defining relations of the view A view supports multiple user perspectives on the database corresponding to different information organizations, avoiding the need for data duplication or information consistency problems Additional motivation: security (privacy concerns, users need only access/modify selected attributes in the data without being able to access the other attributes)

Differences between a Conceptual Database and a View VIEW CONCEPTUAL DATABASE Employee Salary Age Employee Department Salary Birth date Constructable, but not actually present in the database

EXAMPLE: Airline Databases External/USER Conceptual Physical Reservation Department Dispatcher Personnel Dept. Passengers Flights Aircraft Crews Files, Records Bits High level of Abstraction Low level of Abstraction

DATA INDEPENDENCE View1 View2 Viewn Conceptual Database Physical Database Logical Data Independence Many modifications of conceptual scheme can be made without affecting views No Changes in application programs necessary Physical Data Independence Physical schema can be changed without alerting the conceptual level Allows for tuning

Analogy from the programming language world View level Concept Level Physical Level Function f(i) f(i)= m j=1a(i,j) Integer Array A[1..n,1..m] 1 2.. n 3 2 2 5 1 1 2.. m 1 2 6.. m 9 3 1 2 2.. m

VIEW DEFINITIONS Views are defined by a query that generates the desired virtual relation from existing relations: From Department From Employee In Relational Algebra: Create view DEPHEADS As DNAME,DNUMBERS,FNAME,LNAME (EMPLOYEE DEPHEADS DNAME DNO FNAME LNAME MGRSSN=SSN Pebody 5 Robin Wang Admin 4 Jenifer Veallau CS 1 James Borg DEPARTMENT) Views typically include selected projections with optional selects and joins

VIEWS IN SQL CREATE VIEW Defining SQL Query SELECT FROM WHERE DEPHEADS AS DNAME,DNUMBER,FNAME,LNAME Attribute in view relation DEPARTMENT,EMPLOYEE Defining relation DEPARTMENT.MGRSSN=EMPLOYEE.SSN The SQL statement defining view are typically executed at query time, thus additions/changes in the defining/base relations are reflected in the virtual relation (view) transparently. Allow Query a views: SELECT FNAME,LNAME FROM DEPHEADS WHERE DNUMBER=5 The information is a virtual relation is always up to date (automatically reflect database update)

Complex Views Views may include complex calculations CREATE VIEW EMP_AGE(LNAME,AGE) AS Remaining attributes SELECT LNAME,MONTHS-BETWEEN(SYSDATE,BDATE)/12 FROM EMPLOYEE LNAME AGE Built op. SMITH WANG ZELAYA 40.86 50.91 38.12 See Chapter 7 Views creation/definition may contain aggregate operation CREATE VIEW DEPT-INFO(DEPT_NAME,NUM_EMPS,TOTAL_SAL) AS DEPT_NAME NUM EMPLOYER TOTAL SALARY SELECT DNAME,COUNT(*),SUM(SALARY) FROM DEPARTMENT, EMPLOYEE RESEACHER ADMIN HEADQUATER 4 3 1 135,000 93,000 35,000 WHERE DNUMBER=DNO GROUP BY DNAME;

Changes to the database via views UPDATE DEPHEAD SET DNAME = research WHERE LNAME = Wallace OR LNAME = SMITH Syntax: UPDATE SET WHERE <VIEW-NAME> Rename all departments manager by Wallace or Smith to Research <LIST OF CHAGES TO VIEW ATTRIBUTES> <condition based on view attributes> mapped to necessary updates in the defining relation OK if simple name change

PROBLEMS WITH VIEWS Insert into a view based on a join DEPARTMENT Insert into DEPHEADS Values( SALES,6, John, Wilson ) EMPLOYEE DNAME RESEARCH ADMIN SALES DNO 5 4 6 MGRSSN 33344455 98316738 LOC 401 201 FNAME LNAME SSN BDATE ADDRES SAL John Smith James Bary John Wilson 419324 123123 ------ 11,July 223333 10 Nov 111222 ----- ---- 30000 55000 ---- ANOMOLY SELECT LNAME Null values in the fields projected out of the defining relations by the view. SELECT EMPLOYEE.LNAME FROM DEPHEADS FROM DEPARTMENT,EMPLOYEE WHERE DNAME= SALES WHERE MGRSSN=SSN AND DNAME= SALES Fields null result. Join fail because null join attribute

Additional Problem with views UPDATE DEPT_INFO SET TOTAL_SAL = 100000 WHERE DNAME = RESEARCH Problem when view attribute is defined as an aggregate quantity how can the constraint sum(salary)=100000 be realized as an update on the individual salary attributes for dept with > 1 employee

RESTRICTIONS ON VIEWS to avoid consistency problems In general, updates are only allows when there is only one possible update in the base relation to accomplish the view update. 1). A view with a single defining table is updatable, if a) The view attribute contain the primary key and all other not null attributes. (still problem of nulls in the defining relations) 2). Views defines using --- joins --- grouping ---aggregate functions generally not updatable But generally no restrictions on read-only views

View Implementation Issue Strategy #1: QUERY MAPPING Oracle approach Convert query on view to query on base relation Problem: may be inefficient if the view involves complex calculation like aggregate function. Strategy #2: VIEW MATERIALIZATION Create temporary table to reflect the view structure --- efficient if many queries to few updates Temporary table must be updated (recomputed) if updates to the defining relations --- full recomputation costly --- minimal update difficult to determine --- goal of avoiding data duplication

Strategy #1: QUERY MAPPING Convert query on view to query on base relation Problem: may be inefficient if the view involves complex calculation like aggregate function. Strategy #2: VIEW MATERIALIZATION Cache View Implementation Issue Create temporary table to reflect the view structure --- efficient if many queries to few updates Temporary table must be updated (recomputed) if updates to the defining relations --- full recomputation costly --- minimal update difficult to determine (Runtime macro) Oracle approach --- fail to avoid relational count of eliminating data duplication