1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)

Slides:



Advertisements
Similar presentations
Announcements Read 6.1 – 6.3 for Wednesday Project Step 3, due now Homework 5, due Friday 10/22 Project Step 4, due Monday Research paper –List of sources.
Advertisements

Manipulating Functional Dependencies Zaki Malik September 30, 2008.
Dr. Kalpakis CMSC 461, Database Management Systems URL: Relational Database Design.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Functional Dependencies (based on notes by Silberchatz,Korth, and.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Topics to be discusses Functional Dependency Key
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Integrity Constraints (based on notes by Silberchatz,Korth, and.
©Silberschatz, Korth and Sudarshan Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition.
7.1 Chapter 7: Relational Database Design. 7.2 Chapter 7: Relational Database Design Features of Good Relational Design Atomic Domains and First Normal.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Lecture#7 (cont’d): Rel. model - SQL part3.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Integrity Constraints
Multivalued Dependency Prepared by Tomasz Kaciak CS157A.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
CMSC424: Database Design Instructor: Amol Deshpande
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Schema Refinement and Normalization Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 6, 2004 Some slide content.
1 Database Theory and Methodology. 2 The Good and the Bad So far we have not developed any measure of “goodness” to measure the quality of the design,
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#7 : Rel. model - SQL part2 (R&G, chapters.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Relational Database Design
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 7: Relational Database Design. 7.2Unite International CollegeDatabase Management Systems Chapter 7: Relational Database Design Features of Good.
Department of Computer Science and Engineering, HKUST Slide 1 Comp 231 Database Management Systems Comp 231 Database Management Systems 6. Integrity Constraints.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Computing & Information Sciences Kansas State University Monday, 13 Oct 2008CIS 560: Database System Concepts Lecture 18 of 42 Monday, 13 October 2008.
Chapter 7: Relational Database Design. 7.2Unite International CollegeDatabase Management Systems Chapter 7: Relational Database Design Features of Good.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Relational.
Functional Dependencies An example: loan-info= Observe: tuples with the same value for lno will always have the same value for amt We write: lno  amt.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
Computing & Information Sciences Kansas State University Tuesday, 27 Feb 2007CIS 560: Database System Concepts Lecture 18 of 42 Tuesday, 27 February 2007.
Computing & Information Sciences Kansas State University Wednesday, 04 Oct 2006CIS 560: Database System Concepts Lecture 17 of 42 Wednesday, 04 October.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
Ihr Logo Fundamentals of Database Systems Fourth Edition El Masri & Navathe Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 564 Database Management Systems: Design and Implementation Discussion Session Friday, Sept 18, Apul Jain.
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.
1 Lecture 6: Schema refinement: Functional dependencies
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo Lecture#16: Schema Refinement & Normalization.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Minimum Cover of F. Minimal Cover for a Set of FDs Minimal cover G for a set of FDs F: –Closure of F = closure of G. –Right hand side of each FD in G.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Database Design and Normalization (based on notes by Silberchatz,Korth,
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Database design and normalization.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 Dept. of CIS, Temple Univ. CIS661 – Principles of Data Management V. Megalooikonomou Database design and normalization (based on slides by C. Faloutsos.
Computing & Information Sciences Kansas State University Friday, 03 Oct 2007CIS 560: Database System Concepts Lecture 16 of 42 Wednesday, 03 October 2007.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity Constraints Domain Constraints Referential Integrity Assertions Triggers.
Database Management Systems (CS 564)
Functional Dependency
Relational Database Design
Faloutsos & Pavlo SCS /615 Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization.
Lecture #17: Schema Refinement & Normalization - Normal Forms
Temple University – CIS Dept. CIS331– Principles of Database Systems
CSC 453 Database Systems Lecture
Presentation transcript:

1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)

Constraints: Integrity constraints in the E-R Model: Key cardinalities of a Relationship

Overview Domain; Ref. Integrity constraints Assertions and Triggers Functional dependencies

Domain Constraints Domain Types, eg, SQL Fixed Length characters Int; float; (date) null values eg., create table student( ssn char(9) not null,...)

Referential Integrity constraints ‘foreign keys’ - eg: create table takes( ssn char(9) not null, c-id char(5) not null, grade integer, primary key(ssn, c-id), foreign key ssn references student, foreign key c-id references class)

Referential Integrity constraints … foreign key ssn references student, foreign key c-id references class) Effect: expects that ssn exists in ‘student’ table blocks ops that violate that - how?? insertion? deletion/update?

Referential Integrity constraints … foreign key ssn references student on delete cascade on update cascade,... -> eliminate all student enrollments other options (set to null, to default etc)

Weapons for IC: assertions create assertion check triggers (~ assertions with ‘teeth’) on operation, if condition, then action

Triggers - example define trigger zerograde on update takes (if new takes.grade < 0 then takes.grade = 0)

Triggers - discussion more complicated: “managers have higher salaries than their subordinates” - a trigger can automatically boost mgrs salaries triggers: tricky (infinite loops…)

Overview Domain; Ref. Integrity constraints Assertions and Triggers Functional dependencies why definition Armstrong’s “axioms” closure and cover

Functional dependencies motivation: ‘good’ tables takes1 (ssn, c-id, grade, name, address) ‘good’ or ‘bad’?

Functional dependencies takes1 (ssn, c-id, grade, name, address)

Functional dependencies ‘Bad’ - why?

Functional Dependencies Redundancy space inconsistencies insertion/deletion anomalies (later…) What caused the problem?

Functional dependencies ‘name’ depends on the ‘ssn’ define ‘depends’

Functional dependencies Definition: ‘a’ functionally determines ‘b’

Functional dependencies Informally: ‘if you know ‘a’, there is only one ‘b’ to match’

Functional dependencies formally: if two tuples agree on the ‘X’ attribute, they *must* agree on the ‘Y’ attribute, too (eg., if ssn is the same, so should address) … a functional dependency is a generalization of the notion of a key

Functional dependencies ‘X’, ‘Y’ can be sets of attributes other examples??

Functional dependencies ssn -> name, address ssn, c-id -> grade

Functional dependencies K is a superkey for relation R iff K -> R K is a candidate key for relation R iff: K -> R for no a  K, a -> R

Functional dependencies Closure of a set of FD: all implied FDs - eg.: ssn -> name, address ssn, c-id -> grade imply ssn, c-id -> grade, name, address ssn, c-id -> ssn

FDs - Armstrong’s axioms Closure of a set of FD: all implied FDs - eg.: ssn -> name, address ssn, c-id -> grade how to find all the implied ones, systematically?

FDs - Armstrong’s axioms “Armstrong’s axioms” guarantee soundness and completeness: Reflexivity: eg., ssn, name -> ssn Augmentation eg., ssn->name then ssn,grade-> ssn,grade

FDs - Armstrong’s axioms Transitivity ssn->address address-> county-tax-rate THEN: ssn-> county-tax-rate

FDs - Armstrong’s axioms Reflexivity: Augmentation: Transitivity: ‘sound’ and ‘complete’

FDs – finding the closure F+ F + = F repeat for each functional dependency f in F + apply reflexivity and augmentation rules on f add the resulting functional dependencies to F + for each pair of functional dependencies f 1 and f 2 in F + if f 1 and f 2 can be combined using transitivity then add the resulting functional dependency to F + until F + does not change any further We can further simplify manual computation of F + by using the following additional rules.

FDs - Armstrong’s axioms Additional rules: Union Decomposition Pseudo-transitivity

FDs - Armstrong’s axioms Prove ‘Union’ from three axioms:

FDs - Armstrong’s axioms Prove ‘Union’ from three axioms:

FDs - Armstrong’s axioms Prove Pseudo-transitivity:

FDs - Armstrong’s axioms Prove Decomposition

FDs - Closure F+ Given a set F of FD (on a schema) F+ is the set of all implied FD. Eg., takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address }F}F

FDs - Closure F+ ssn, c-id -> grade ssn-> name, address ssn-> ssn ssn, c-id-> address c-id, address-> c-id... F+

FDs - Closure F+ R=(A,B,C,G,H,I) F= { A->B A->C CG->H CG->I B->H} Some members of F+: A->H AG->I CG->HI

FDs - Closure A+ Given a set F of FD (on a schema) A+ is the set of all attributes determined by A: takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {ssn}+ =?? }F}F

FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {ssn}+ ={ssn, name, address } }F}F

FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {c-id}+ = ?? }F}F

FDs - Closure A+ takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address {c-id, ssn}+ = ?? }F}F

FDs - Closure A+ if A+ = {all attributes of table} then ‘A’ is a candidate key

FDs - Closure A+ Algorithm to compute  +, the closure of  under F result :=  ; while (changes to result) do for each    in F do begin if   result then result := result   end

FDs - Closure A+ (example) R = (A, B, C, G, H, I) F = {A  B, A  C, CG  H, CG  I, B  H} (AG) + 1.result = AG 2.result = ABCG(A  C and A  B) 3.result = ABCGH(CG  H and CG  AGBC) 4.result = ABCGHI(CG  I and CG  AGBCH) Is AG a candidate key? 1. Is AG a super key? 1. Does AG  R? 2. Is any subset of AG a superkey? 1. Does A +  R? 2. Does G +  R?

FDs - A+ closure Diagrams AB->C (1) A->BC (2) B->C (3) A->B (4) C A B

FDs - ‘canonical cover’ Fc Given a set F of FD (on a schema) Fc is a minimal set of equivalent FD. Eg., takes(ssn, c-id, grade, name, address) ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F

FDs - ‘canonical cover’ Fc ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F Fc

FDs - ‘canonical cover’ Fc why do we need it? define it properly compute it efficiently

FDs - ‘canonical cover’ Fc why do we need it? easier to compute candidate keys define it properly compute it efficiently

FDs - ‘canonical cover’ Fc define it properly - three properties every FD a->b has no extraneous attributes on the RHS ditto for the LHS all LHS parts are unique

‘extraneous’ attribute: if the closure is the same, before and after its elimination or if F-before implies F-after and vice-versa FDs - ‘canonical cover’ Fc

ssn, c-id -> grade ssn-> name, address ssn,name-> name, address ssn, c-id-> grade, name F

FDs - ‘canonical cover’ Fc Algorithm: examine each FD; drop extraneous LHS or RHS attributes merge FDs with same LHS repeat until no change

FDs - ‘canonical cover’ Fc Trace algo for AB->C (1) A->BC (2) B->C (3) A->B (4)

FDs - ‘canonical cover’ Fc Trace algo for AB->C (1) A->BC (2) B->C (3) A->B (4) (4) and (2) merge: AB->C (1) A->BC (2) B->C (3)

FDs - ‘canonical cover’ Fc AB->C (1) A->BC (2) B->C (3) in (2): ‘C’ is extr. AB->C (1) A->B (2’) B->C (3)

FDs - ‘canonical cover’ Fc AB->C (1) A->B (2’) B->C (3) in (1): ‘A’ is extr. B->C (1’) A->B (2’) B->C (3)

FDs - ‘canonical cover’ Fc B->C (1’) A->B (2’) B->C (3) (1’) and (3) merge A->B (2’) B->C (3) nothing is extraneous: ‘canonical cover’

FDs - ‘canonical cover’ Fc AFTER A->B (2’) B->C (3) BEFORE AB->C (1) A->BC (2) B->C (3) A->B (4)

Overview - conclusions Domain; Ref. Integrity constraints Assertions and Triggers Functional dependencies why definition Armstrong’s “axioms” closure and cover