Www.techstudent.co.cc Unit III. www.techstudent.co.cc Views A table that is derived from other tables Considered as a virtual table Does not store data.

Slides:



Advertisements
Similar presentations
DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
Advertisements

Relational data integrity
Data manipulation operations on views 1. 2 Outline retrieval operations in theory in practice (SQL92 and PostgreSQL) update operations in theory - basics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
primary key constraint foreign key constraint
Database Administration, Integrity and Performance.
Chapter 3 Notes. 3.1 Functional Dependencies A functional dependency is a statement that – two tuples of a relation that agree on some particular set.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
Databases 6: Normalization
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Chapter 14 Advanced Normalization Transparencies © Pearson Education Limited 1995, 2005.
Midterm 1 Concepts Relational Algebra (DB4) SQL Querying and updating (DB5) Constraints and Triggers (DB11) Unified Modeling Language (DB9) Relational.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
Department of Computer Science and Engineering, HKUST Slide 1 Comp 231 Database Management Systems Comp 231 Database Management Systems 6. Integrity Constraints.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
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.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
CSCD34 - Data Management Systems - A. Vaisman1 Schema Refinement and Normal Forms.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
1 Context “Updating Union, Intersection and Difference views” - introduces a systematic approach to updating a view formed specifically by using  Union.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
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.
Christoph F. Eick: Functional Dependencies, BCNF, and Normalization 1 Functional Dependencies, BCNF and Normalization.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Lecture 8: Database Concepts May 4, Outline From last lecture: creating views Normalization.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 15.
Advanced Relational Algebra & SQL (Part1 )
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
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.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
Ch 7: Normalization-Part 1
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
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.
11/06/97J-1 Principles of Relational Design Chapter 12.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter (6) The Relational Algebra and Relational Calculus Objectives
Chapter 6: Integrity (and Security)
Advanced Normalization
Chapter 10 Views.
STRUCTURE OF PRESENTATION :
Advanced Normalization
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Structured Query Language (3)
So What are Views and Triggers anyway?
Database SQL.
Presentation transcript:

Unit III

Views A table that is derived from other tables Considered as a virtual table Does not store data physically

Views in SQL The syntax CREATE VIEW "VIEW_NAME" AS "SQL Statement"

Views in SQL CREATE VIEW DEPT_INFO AS SELECT DNAME, COUNT(*), SUM(SALARY) FROM DEPARTMENT, EMPLOYEE WHERE DNUM = DNO GROUP BY DNAME;

Views in SQL ADV: –Simplification of certain queries –Can also be used as a security mechanism View is always up-to-date. To dispose a view, DROP VIEW is used

Updation in Views A view with single defining table is updatable if the view attributes contain the primary key or some other key of the base relation. Views defined on multiple tables using joins are not updatable Views defined using grouping and aggregate functions are not updatable

Need for views Views provide a shorthand or “macro” capability Allow the same data to be seen by different users in different ways at the same time Provide automatic security for hidden data Views can provide logical data independence

Views Principle of Interchangability –There must be no arbitrary and unnecessary distinctions between tables and views. Principle of Database Relativity –User works with a mixture of base tables and views called an expressible database.

View Retrievals Let D be a database and V be a view on D V = X ( D ) –Expression X is some funnction on D Let RO be a retrieval operation on V. The result of the retreival is RO (V ) = RO ( X ( D ) ) Thus the result of retrieval is equal to the result of applying X to D

View Retrievals Retrieval can be of two methods –Materialization Materializing a copy of the relation that is the current value of view V and then applying RO to that materialized copy –Substitution Materialization cannot be used for update operations Substitution is quite straightforward and works well in theory

View Updates View updatability is a semantic issue. Not a syntactic one. View updation must work correctly in the special case when the view in a base relvar The updating rules must preserve symmetry where applicable. The updating rules must take into account any applicable triggered actions, including in particular referential actions such as cascade delete

View Updates It is desirable to regard UPDATE as a short hand for DELETE-INSERT sequence. All updates on views must be implemented by the same kind of updates on the underlying relvars. Rules must be capable of recursive application. I.e, updates on views are all or nothing.

View Updates Union:Union: Insert Rule for A UNION B –The new tuple must satisfy PA or PB or both. If it satisfies PA, it is inserted into A. If it is satisfies PB, it is inserted into B, unless it was inserted into B already as a side effect of inserting it into A

View Updates UnionUnion Delete Rule for A UNION B –If the tuple to be deleted appears in A, it is deleted from A. If it appears in B, it is deleted from B

View Updates UnionUnion Update Rule for A UNION B –The tuple to be updated must be such that the updated version satisfies PA or PB or both. –If the tuple to be updated appears in A, it is deleted from A without performing any triggered actions and without checking the predicate for A. This may have the side effect of deleting from B also.

Contd… Union Update Rule for A UNION B –If the tuple (still) appears in B, it is deleted from B. –If the updated version of the tuple satisfies PA, it is inserted into A. If the updated version satisfies PB, it is inserted into B, unless it is inserted into B already as a side effect of inserting it into A

View Updates IntersectIntersect INSERT –The new tuple must satisfy both PA and PB. If it does not currently appear in A, it is inserted into A. If it (still) does not appear in B, it is inserted into B. DELETE –The tuple to be deleted is deleted from A. If it (still) appears in B, it is deleted from B.

View Updates UPDATE –The tuple to be updated must be such that the updated version satisfies both PA and PB. The tuple is deleted from A without performing any triggered actions or predicate checks. If it (still) appears in B, it is deleted from B If the updated version of the tuple does not currently appear in A, it is inserted into A. If it does not appear in B, it is inserted into B

View Updates Difference Rules for updating A MINUS B INSERT: The new tuple must satisfy PA and not PB. It is inserted into A DELETE: The tuple to be deleted is deleted from A UPDATE: The tuple to be updated must be such that the updated version satisfies PA and not PB.The tuple is deleted from A and the updated version is inserted into A

View Updates- Project Let X and Y be two groups of attributes on relation A. Consider the projection of A over X. A{X} INSERT : Let the tuple to be inserted be {x}. Let the default value of Y be y. The tuple (x,y) is inserted into A. (If no default values exists, it is an error

View Updates- Project DELETE : All tuples of A with the same X value as the tuple to be deleted from A{X} are deleted from A UPDATE: Let the tuple to be updated be (x)and the updated version is (x’). Let a be a tuple of A with the same X value x, and let the value of Y in a be y. All such tuples a are deleted from A. Then for each value y, the tuple (x’, y) is inserted into A

View Updates - Join Consider the join J = A JOIN B where A, B and J have the headings {X, Y}, {Y,Z} and {X, Y, Z} respectively. Let the predicates for A and B be PA and PB respectively. Then Predicate for J is PJ and is equal to PA(a) and PB(b)

View Updates- JOIN INSERT: The new tuple j must satisfy PJ. If the A portion of j does not appear in A, it is inserted into A. If B portion of j does not appear in B, it is inserted into B DELETE: The A portion of the tuple to be deleted is deleted from A and the B portion is deleted from B

View Updates- JOIN UPDATE: The tuple to be updated must satisfy PJ. The A portion is deleted from A and the B portion is deleted from B. If the A portion of the updated version does not appear in A, it is inserted into A. If the B portion does not appear in B, it is inserted into B.

View Updates- JOIN Implications of the rule for the cases –One-to-one –One-to-many –Many-to-many

Functional Dependencies

Definition Let r be a relation and let X and Y be arbitrary subsets of the set of attributes of r. Then, Y is functionally dependent on X if and only if each X value in r has associated with it precisely one Y value in r. It is written symbolically as X Y In other words whenever two tuples of r agree on their X value, they also agree on their Y value

Trivial and Nontrivial Dependency A dependency is trivial if it cannot possibly fail to be satisfied. A dependency is trivial if and only if the right side is a subset of the left side.

Closure of a set of dependencies The set of all FDs that are implied by a given set S of FDs is called the closure of S, written as S +. Armstrong’s axioms allow to compute S + from S Armstrong’s axioms A set of inference rules by which new FDs can be inferred from given ones