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.

Slides:



Advertisements
Similar presentations
primary key constraint foreign key constraint
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Manipulating Functional Dependencies Zaki Malik September 30, 2008.
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.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
Functional Dependencies and Normalization for Relational Databases.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
The Relational Model System Development Life Cycle Normalisation
Multivalued Dependency Prepared by Tomasz Kaciak CS157A.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
1 Database Design Theory Which tables to have in a database Normalization.
Logical Model Agenda - Informal Mapping ER-Diagram to Schemas
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
1 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Schema Refinement and Normalization Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 6, 2004 Some slide content.
Databases 6: Normalization
Functional Dependencies CS 186, Spring 2006, Lecture 21 R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
FUNCTIONAL DEPENDENCIES. Chapter Outline 1 Informal Design Guidelines for Relational Databases 1.1Semantics of the Relation Attributes 1.2 Redundant Information.
Instructor: Churee Techawut Functional Dependencies and Normalization for Relational Databases Chapter 4 CS (204)321 Database System I.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
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.
1 Lecture 6: Schema refinement: Functional dependencies
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
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.
1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Schema Refinement SHIRAJ MOHAMED M | MIS 1. Learning Objectives  Identify update, insertion and deletion anomalies  Identify possible keys given an.
Lecture 8: Database Concepts May 4, Outline From last lecture: creating views Normalization.
Deanship of Distance Learning Avicenna Center for E-Learning 1 Session - 7 Sequence - 2 Normalization Functional Dependencies Presented by: Dr. Samir Tartir.
1 Functional Dependencies. 2 Motivation v E/R  Relational translation problems : –Often discover more “detailed” constraints after translation (upcoming.
Functional Dependencies R&G Chapter 19 Science is the knowledge of consequences, and dependence of one fact upon another. Thomas Hobbes ( )
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
ICS 421 Spring 2010 Relational Model & Normal Forms Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1/19/20101Lipyeow.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 5 Introduction to a First Course in Database Systems.
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.
© 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.
11/06/97J-1 Principles of Relational Design Chapter 12.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Functional Dependencies and Normalization for Relational Databases 1 Chapter 15 تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في.
Chapter 10 Functional Dependencies and Normalization for Relational Databases Copyright © 2004 Pearson Education, Inc.
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Functional Dependency and Normalization
Database Management Systems (CS 564)
Schema Refinement & Normalization Theory
Normalization Murali Mani.
Functional Dependencies
Normalization cs3431.
Chapter 19 (part 1) Functional Dependencies
Relational Database Theory
Presentation transcript:

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 based on functional dependencies.  Why is a logical design needed?  Relations translated from ER may have introduced data redundancy which leads to inconsistencies and update anomalies.  What is involved in logical design?  Check for normal forms  If necessary, decompose relations

Lecture 6Logical Database Design (1)3 A Database with Redundancy Assume all students of same major are assigned to the same academic advisor. Students  (FD): major  Advisor, Office  What problems does it have?

Lecture 6Logical Database Design (1)4 Update Anomalies  Insertion anomaly: How to add a new major?  Modification anomaly: What would happen if we change office of Smith in the first tuple?  Deletion anomaly: What would happen if Scott is deleted? Students

Lecture 6Logical Database Design (1)5 A Better Design  Decompose Students into two relations Major_Advisor Students  Decomposition can remove redundancy  It may also cause problems if not done carefully.

Lecture 6Logical Database Design (1)6 Cardinality Ratio  The number of relationship instances that an entity can participate in.  There are three:  One-to-one (1:1)  One-to-Many (1:M)  Many-to-many (M:N)  Note: “1” may mean either zero or one and “many” may mean zero to the DBMS maximum

Lecture 6Logical Database Design (1)7 1:1 Relationships  A one-to-one relationship simply means that for any single instance of one entity, it may participate in zero or one instance in the related entity  E.g. Employee manages Department  An employee may or may not be a department manager, however, each department needs one manager  Employee has partial participation, generally a department would have total participation

Lecture 6Logical Database Design (1)8 1:1 Relationships  The foreign key should be placed in the entity with total participation  If both have total participation, the location of the foreign key is arbitrary  Additionally, if both participations are total, the two entities may be merged  Why would you not want to do this?  Access Restrictions  Special Attributes  Referenced by another entity  Performance in Distributed Databases

Lecture 6Logical Database Design (1)9 1:1 Relationships  Access Restrictions  Special Attributes  Referenced by another entity SalaryMed RecsEmp_ID AIRLINE EMPLOYEES 1 1 Flying HoursEmp_ID 1 Pilots only! Confidential! Tool Bag IDColorEmp_IDJobStartDateAddressTool Bag IDStorage BinTool Bag ID Maint only!

Lecture 6Logical Database Design (1)10 1:M Relationships  A one-to-many relationship means that for any single instance of one entity, it may participate in zero or more instances in the related entity, but the related entity may only participate in zero or one instance.  Subordinate to supervisor. Each subordinate generally will have one supervisor, but each supervisor usually may have zero or more employees.  Not absolute! Sometimes a subordinate may have >1 supervisors – consider this in design!

Lecture 6Logical Database Design (1)11 1:M Relationships  The foreign key always goes in the “many” part of the relationship!  This is counter-intuitive, be careful!  The FK must always reference a PK in the related entity or be null.  referential integrity  What results from placing the FK in the “one” part of the relationship?  Can part of a PK also be a FK?  That coupled with the “existence dependancy” indicates which type of entity?

Lecture 6Logical Database Design (1)12 1:M Relationship Design Thought  Consider the attribute “class” of a STUDENT entity. Given that all possible values are “Freshman”, “Sophomore”, “Junior”, “Senior”, or “Grad Student.” Is there any reason to place it in its own separate entity?

Lecture 6Logical Database Design (1)13 M:N Relationships  A many-to-many relationship means that for any single instance of one entity, it may participate in zero or more instances in the related entity, and the related entity may participate in zero or more instances as well.  Subordinate to supervisor. Consider allowing each subordinate to have zero or more supervisors.  Now where does the FK go?

Lecture 6Logical Database Design (1)14 M:N Relationships  Actually, there are two FKs, one for each entity.  These two keys are placed in their own entity.  Together they make up the PK of that entity.  In this case, all FKs must reference a valid PK in the related entity – why?  This entity may be called a link table, join table, junction table, or simply many-to-many relationship.

Lecture 6Logical Database Design (1)15 M:N Relationships  The link table may contain it’s own attributes.  For example, an evaluation by a supervisor.  That evaluation may NOT go in the subordinate entity, because there may be others from different supervisors.  It can not go in the supervisor entity because there may be more than one subordinate.  Only the subordinate/supervisor entities together can uniquely determine that evaluation.  Consider course grade vs. G.P.A.

Lecture 6Logical Database Design (1)16 Functional Dependencies (FDs)  Let R(A1,..., An) be a relation schema. Let X and Y be two subsets of {A1,..., An}, i.e., X, Y  R. R satisfies a functional dependency, denoted by X  Y, if in every legal instance r(R), for any pair of tuples t1 and t2 in r(R), if t1[X] = t2[X], then t1[Y] = t2[Y].  If X  Y, we say that “X (functionally) determines Y”.  X may also be called a determinant  FDs are about ALL states of a relation.

Lecture 6Logical Database Design (1)17 An Example of FDs  Consider a relation Student(SID, Name, Address, Phone, Major) Some FDs may be: S  NM, NA  P, …  Notations  Use single letter for attributes, i.e., S for SID, N for Name, A for Address, …  Use the relation name for the set of attributes of relation, i.e., Students for {SNAPM}

Lecture 6Logical Database Design (1)18 Properties of FDs  X  Y says redundant X-values always cause the redundancy of Y-values.  FDs are given by DBAs or DB designers.  FDs are enforced/guaranteed by DBMS.  Given an instance r of a relation R, we can only determine that some FD is not satisfied by R, but can not determine if an FD is satisfied by R.

Lecture 6Logical Database Design (1)19 Alternative Definitions of FDs*  R satisfies X  Y if whenever two tuples in any instance of R have the same X-value, they must also have the same Y-value.  R satisfies X  Y if there exist no two tuples in any instance of R such that they have the same X-value but different Y- values.  R satisfies X  Y if each distinct X-value corresponds to a unique Y-value in any r(R).

Lecture 6Logical Database Design (1)20 Which FD is satisfied?  Which FD does R(A, B, C, D) satisfy, if the following instance is the only instance of R? A  B, A  C, C  A, A  D, B  D, AB  D R

Lecture 6Logical Database Design (1)21 Closure of FDs  Given some FDs, new FDs can often be inferred. E.g., from S  NM and M  D, we can infer S  D. Let F be a set of FDs satisfied by R, and X, Y, K be subsets of attributes of R.  F (logically) implies X  Y if whenever R satisfies (all FDs in) F, R also satisfies X  Y.  The closure of F, denoted by F +, is the set of FDs implied by F, that is, F + = {X  Y | F implies X  Y}.

Lecture 6Logical Database Design (1)22 Candidate Key & Trivial FDs  Let F be a set of FDs satisfied by R, and K  R. K is a candidate key (CK) of R if  K  R is in F + (i.e., F implies K  R); and  there is no X  K, such that X  R is also in F + (minimality). (no part of K  R )  An FD X  Y is trivial if Y  X.  Some trivial FDs are: AB  B, A  ,   .  Find the candidate keys and trivial FDs in the next example. What is ABC?

Lecture 6Logical Database Design (1)23 F + : An Example * Example: Let F = {AB  C, C  B} be a set of FDs satisfied by R(A, B, C). F + = {A  , A  A, AB  , AB  A, AB  B, AB  C, AB  AB, AB  AC, AB  BC, AB  ABC, AC  , AC  A, AC  B, AC  C, AC  AB, AC  AC, AC  BC, AC  ABC, ABC  , ABC  A, ABC  B, ABC  C, ABC  AB, ABC  AC, ABC  BC, ABC  ABC, B  , B  B, BC  , BC  B, BC  C, BC  BC, C  , C  B, C  C, C  BC,    }

Lecture 6Logical Database Design (1)24 Inference Rules for FDs Let F be a set of FDs satisfied by R, and X, Y, Z  R.  Armstrong’s Axioms (1974) for deriving new FDs (IR1) Reflexivity: If X  Y, then X  Y is satisfied by R. (IR2) Augmentation: If X  Y is satisfied by R, then XZ  YZ is also satisfied by R. (IR3) Transitivity: If X  Y and Y  Z are satisfied by R, then so is X  Z.

Lecture 6Logical Database Design (1)25 Compute FD Closure F +  Let F be a set of FDs. To compute F +, start with FDs in F, repeatedly apply IR1-IR3, until no new FD can be derived. Theorem: Armstrong's Axioms are sound and complete.  Sound: no incorrect FD will be added to F +.  Complete: all FDs in F + will be generated.

Lecture 6Logical Database Design (1)26 Additional Axioms  Additional rules derivable from Armstrong's Axioms. (IR4) Decomposition: { X  YZ }  { X  Y, X  Z } (IR5) Union: { X  Y, X  Z }  X  YZ (IR6) Pseudotransitivity: { X  Y, WY  Z }  WX  Z

Lecture 6Logical Database Design (1)27 Closure of Attributes How to determine if F implies X  Y?  Method 1: Check if X  Y is in F +.  Problem: F + is too expensive to compute!  Method 2: Compute closure of X under F. X + = { A |= X  A  F + }  X + is the set of attributes that are functionally determined by X under F. Theorem: X  Y  F + if and only if Y  X +. Proof: Use IR4 & IR5.