STRUCTURE OF PRESENTATION :

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

Copyright © C. J. Date 2005page 1 AGENDA : 1. A few preliminaries 2. Laying the foundations 3.Building on the foundations.
Copyright © C. J. Date 2005page 97 S#Y S1DURINGS3DURING [d04:d10][d08:d10] S2DURINGS4DURING [d02:d04][d04:d10] [d08:d10] WITH ( EXTEND T2 ADD ( COLLAPSE.
1 Constraints, Triggers and Active Databases Chapter 9.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
Chapter 3 An Introduction to Relational Databases.
Database Management System Module 3:. Complex Constraints In this we specify complex integrity constraints included in SQL. It relates to integrity constraints.
SQL Constraints and Triggers
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Chapter 3 An Introduction to Relational Databases.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5 (cont.)
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 157 Database Systems I SQL Constraints and Triggers.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Midterm 1 Concepts Relational Algebra (DB4) SQL Querying and updating (DB5) Constraints and Triggers (DB11) Unified Modeling Language (DB9) Relational.
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
Database Systems Lecture # 8 11 th Feb,2011. The Relational Model of Data The term relation is basically just a mathematical term for a table. DBMS products.
Chapter 3 An Introduction to Relational Databases.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Ad Hoc Constraints Objectives of the Lecture : To consider Ad Hoc Constraints in principle; To consider Ad Hoc Constraints in SQL; To consider other aspects.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Data Integrity An empty database is a correct database.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
Unit III. Views A table that is derived from other tables Considered as a virtual table Does not store data.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
Constraints, Triggers and Views COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the constraints.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
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.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
1 CS 430 Database Theory Winter 2005 Lecture 7: Designing a Database Logical Level.
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.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Chapter 3 An Introduction to Relational Databases.
1 CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 8 Relational Calculus.
STRUCTURE OF PRESENTATION :
SQL – Part 2.
COP Introduction to Database Structures
Databases We are particularly interested in relational databases
Chapter 10 Views.
Normalization Karolina muszyńska
Constraints and Triggers
Active Database Concepts
Foreign Keys Local and Global Constraints Triggers
for Computer Professionals
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
SQL: Structured Query Language (‘Sequel’)
Mathematical Structures for Computer Science Chapter 1
Chapter 14 Normalization – Part I Pearson Education © 2009.
Introduction to Relational Databases
Dealing with Uniqueness Constraint in Query Optimization
CMSC-461 Database Management Systems
Unit 7 Normalization (表格正規化).
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
SQL – Constraints & Triggers
Question 1: Basic Concepts (45 %)
STRUCTURE OF PRESENTATION :
Chapter 7a: Overview of Database Design -- Normalization
Assertions and Triggers
Presentation transcript:

STRUCTURE OF PRESENTATION : 1. Basic database concepts ** Entr’acte 2. Relations 8. SQL tables 3. Keys and foreign keys 9. SQL operators I 4. Relational operators I 10. SQL operators II Relational operators II 11. Constraints and predicates 12. The relational model A. SQL constraints SQL vs. the relational model References Copyright C. J. Date 2013

INTEGRITY CONSTRAINTS : An integrity constraint is, loosely, a boolean expression that must evaluate to TRUE Any attempt to update the DB in such a way as to cause some constraint to evaluate to FALSE must fail … … and, in the relational model, fail IMMEDIATELY !!! /* this is The Golden Rule */ We’ve already talked about key and foreign key constraints, but constraints of arbitrary complexity are possible, and do indeed occur in practice (“business rules”) ... and they’re IMPORTANT! Copyright C. J. Date 2013

EXAMPLES : 1. Supplier status values must be in the range 1 to 100 inclusive: CONSTRAINT CX1 IS_EMPTY ( S WHERE STATUS < 1 OR STATUS > 100 ) ; Or: CONSTRAINT CX1 AND ( S , STATUS ≥ 1 AND STATUS ≤ 100 ) ; Note: AND here could reasonably be pronounced “for all” Copyright C. J. Date 2013

2. Suppliers in London must have status 20: CONSTRAINT CX2 IS_EMPTY ( S WHERE CITY = 'London' AND STATUS  20 ) ; Or: CONSTRAINT CX2 AND ( S , CITY  'London' OR STATUS = 20 ) ; Copyright C. J. Date 2013

3. Supplier numbers must be unique: CONSTRAINT CX3 COUNT ( S ) = COUNT ( S { SNO } ) ; In practice would use KEY shorthand /* see earlier */ Copyright C. J. Date 2013

4. Suppliers with status less than 20 aren’t allowed to supply part P6: CONSTRAINT CX4 IS_EMPTY ( ( S JOIN SP ) WHERE STATUS < 20 AND PNO = 'P6' ) ; /* multirelvar constraint */ /* checking in SQL would probably be DEFERRED ... violates Golden Rule !!! */ Copyright C. J. Date 2013

5. Every supplier number in SP must also appear in S: CONSTRAINT CX5 SP { SNO }  S { SNO } ; Foreign key constraint from SP to S In practice would use FOREIGN KEY shorthand Copyright C. J. Date 2013

(Very important!) WAY OF THINKING ABOUT RELVARS : Heading corresponds to a predicate (truth valued function): e.g., Supplier SNO is under contract, is named SNAME, has status STATUS, and is located in city CITY Parameters (SNO, SNAME, STATUS, CITY in the example) stand for values of the relevant types Tuples represent true propositions (“instantiations” of the predicate that evaluate to TRUE), obtained by substituting arguments for the parameters: e.g., Supplier S1 is under contract, is named Smith, has status 20, and is located in city London Copyright C. J. Date 2013

THUS : Every relvar has an associated relvar predicate (or meaning or intended interpretation or intension) If relvar R has predicate P, then every tuple t in R at time x represents proposition p, derived by invoking (or instantiating) P at time x with t’s attribute values as arguments Body of R at time x is extension of P at time x The Closed World Assumption: Relvar R contains, at any given time, all and only the tuples that represent true propositions (true instantiations of the predicate for R) at the time in question Loosely: Everything the DB says (or implies) is true, everything else is false Copyright C. J. Date 2013

RELATIONS are (true) statements about those things! RELATIONS vs. TYPES : TYPES are sets of things we can talk about; RELATIONS are (true) statements about those things! Note three very important corollaries ... Copyright C. J. Date 2013

1. Types and relations are both NECESSARY They’re not the same thing They’re SUFFICIENT (as well as necessary)* A DB (plus its operators) is a logical system !!! This was Codd’s great insight ... and it’s why RM is rock solid, and “right,” and will endure ... and why other “data models” are just not in the same ballpark * Need relvars too for changes over time Copyright C. J. Date 2013

PREDICATES vs. CONSTRAINTS : Relvar predicate for R is “intended interpretation” for R … but it (and corresponding propositions) aren’t and can’t be understood by the system System can’t know what it means for a “supplier” to “be located” somewhere, etc.—that’s interpretation System can’t know a priori whether what the user tells it is true!—can only check the integrity constraints ... If OK, system accepts user assertion as true from this point forward System can’t enforce truth, only consistency !!! Copyright C. J. Date 2013

Correct implies consistent Converse not true Inconsistent implies incorrect DB is correct if and only if it fully reflects the true state of affairs in the real world ... but the best the system can do is ensure the DB is consistent (= satisfies all known integrity constraints) Copyright C. J. Date 2013

EXERCISES : Give (plausible) predicates for relvars S, P, and SP. Which operations have the potential to violate constraints CX1-CX5 ? CX1: Status values must be in the range 1 to 100 inclusive CX2: Suppliers in London must have status 20 CX3: Supplier numbers must be unique CX4: Suppliers with status less than 20 aren’t allowed to supply P6 CX5: Every supplier number in SP must also appear in S Copyright C. J. Date 2013