LOGICAL DATABASE DESIGN Part #1/2

Similar documents
UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

CSIT5300: Advanced Database Systems

Relational Database Design

Database Design: Normal Forms as Quality Criteria. Functional Dependencies Normal Forms Design and Normal forms

COSC 430 Advanced Database Topics. Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19

Relational-Database Design

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 10. Logical consequence (implication) Implication problem for fds

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein

Constraints: Functional Dependencies

Functional Dependencies. Getting a good DB design Lisa Ball November 2012

Functional. Dependencies. Functional Dependency. Definition. Motivation: Definition 11/12/2013

Functional Dependencies & Normalization. Dr. Bassam Hammo

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

Constraints: Functional Dependencies

CS54100: Database Systems

Design theory for relational databases

Functional Dependencies

Schema Refinement. Feb 4, 2010

Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms

Detecting Functional Dependencies Felix Naumann

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design

11/6/11. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Schema Refinement and Normal Forms

Schema Refinement & Normalization Theory

Functional Dependencies

CMPS Advanced Database Systems. Dr. Chengwei Lei CEECS California State University, Bakersfield

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Functional Dependencies and Normalization

Comp 5311 Database Management Systems. 5. Functional Dependencies Exercises

Functional Dependency and Algorithmic Decomposition

INF1383 -Bancos de Dados

CSC 261/461 Database Systems Lecture 13. Spring 2018

Background: Functional Dependencies. æ We are always talking about a relation R, with a æxed schema èset of attributesè and a

Chapter 3 Design Theory for Relational Databases

Relational Design Theory I. Functional Dependencies: why? Redundancy and Anomalies I. Functional Dependencies

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007

CSE 344 MAY 16 TH NORMALIZATION

Schema Refinement and Normal Forms. Case Study: The Internet Shop. Redundant Storage! Yanlei Diao UMass Amherst November 1 & 6, 2007

Normalization. October 5, Chapter 19. CS445 Pacific University 1 10/05/17

Database Design and Implementation

CSE 344 AUGUST 3 RD NORMALIZATION

Schema Refinement: Other Dependencies and Higher Normal Forms

Chapter 3 Design Theory for Relational Databases

Design Theory for Relational Databases

Introduction to Data Management. Lecture #6 (Relational DB Design Theory)

Functional Dependencies

Schema Refinement and Normal Forms

CSE 132B Database Systems Applications

Kapitel 3: Formal Design

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies?

Schema Refinement and Normalization

Schema Refinement and Normal Forms

Chapter 2 Combinational Logic Circuits

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties

Schema Refinement and Normal Forms. Why schema refinement?

Schema Refinement and Normal Forms Chapter 19

CHAPTER 3 BOOLEAN ALGEBRA

Functional Dependencies and Normalization

Lecture 6: Manipulation of Algebraic Functions, Boolean Algebra, Karnaugh Maps

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database

Introduction to Database Systems CSE 414. Lecture 20: Design Theory

Design Theory for Relational Databases

Relational Design: Characteristics of Well-designed DB

Practice and Applications of Data Management CMPSCI 345. Lecture 15: Functional Dependencies

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Chapter 8: Relational Database Design

Information Systems for Engineers. Exercise 8. ETH Zurich, Fall Semester Hand-out Due

Schema Refinement and Normal Forms

Data Dependencies in the Presence of Difference

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Chapter 7: Relational Database Design

Database Design and Normalization

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design

Identity. "At least one dog has fleas" is translated by an existential quantifier"

Introduction to Management CSE 344

Schema Refinement and Normal Forms. Chapter 19

Global Database Design based on Storage Space and Update Time Minimization

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram

SCHEMA NORMALIZATION. CS 564- Fall 2015

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Homework 1/Solutions. Graded Exercises

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd.

Introduction to Data Management CSE 344

Functional Dependency Theory II. Winter Lecture 21

Databases 2012 Normalization

Information Systems (Informationssysteme)

Relational Database Design

FUNCTIONAL DEPENDENCY THEORY II. CS121: Relational Databases Fall 2018 Lecture 20

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) [R&G] Chapter 19

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004

12/3/2010 REVIEW ALGEBRA. Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000

Functional Dependencies

Desirable properties of decompositions 1. Decomposition of relational schemes. Desirable properties of decompositions 3

Lecture 15 10/02/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

CSE 544 Principles of Database Management Systems

Transcription:

LOGICAL DATABASE DESIGN Part #1/2 Functional Dependencies Informally, a FD appears when the values of a set of attributes uniquely determines the values of another set of attributes. Example: schedule (PILOT, FLIGHT#, DATE, TIME) 1. TIME functionally depends upon FLIGHT# 2. PILOT functionally depends upon {FLIGHT#, DATE} 3. FLIGHT# functionally depends upon {PILOT, DATE, TIME} OR 1. FLIGHT# uniquely determines TIME 2. {FLIGHT#, DATE} uniquely determines PILOT 3. {PILOT, DATE, TIME} uniquely determines FLIGHT# OR 1. FLIGHT# TIME 2. {FLIGHT#, DATE} PILOT 3. {PILOT, DATE, TIME} FLIGHT# Note, the " " sign is read "functionally determines" Formal Definition: Let r(r), X R, and Y R. Let s(x) = Π X (r) and q(y) = Π Y (r). Dr. Byunggu Yu 1

There is a FD X Y for every state of r if the mapping f:s(x) q(y) is a function. s(x) q(y) - In algebraic sense, r(r) satisfies the FD X Y, if Π Y (σ X=X' (r)) always produces at most one tuple. (Note, X' is values of the set of attributes X.) Properties of FDs 1. If X Y, then t1, t2 r(r), t1[y]=t2[y] if t1[x]=t2[x]. 2. FD is a time invariant property of a relation r, i.e. it holds for all states of r. Discussion - If X is a key of r (R), then for arbitrary Y R, r satisfies the FD X Y. Dr. Byunggu Yu 2

- If the relationship cardinality between Π X (R) and Π Y (r) is manyto-one, then r satisfies X Y (if the relationship is 1-to-1, then Y X holds too.) - Looking at the current contents of a relation, one cannot prove the existence of a FD; but it is sometimes possible to say which FDs are not satisfied. - FDs are statements about the real world made by the DBA in accordance with the semantics of the attributes and the reality which is modeled. - FDs are axioms about the world which cannot be proven. - Most DBMSs preserve the FDs of the form Key Attributes, but some systems are capable of enforcing all FDs specified by the DBA. Trivial FD and Nontrivial FD supplies (S_NAME, S_ADDR, PART#, PRICE) - Nontrivial FDs: 1. S_NAME ADDR (if only one address is important) 2. {S_NAME, PART#} PRICE Dr. Byunggu Yu 3

- Trivial FDs: S_NAME S_NAME {S_NAME, ADDR} S_NAME {S_NAME, ADDR} ADDR {S_NAME, PART#} S_NAME {S_NAME, PART#} PART#.. Note, A B is trivial if and only if B A - From Nontrivial FDs 1 and 2, one can derive {S_NAME, PART#} {ADDR, PRICE} Note, {S_NAME, PART#} is a key of the relation "supplies" and, therefore, it functionally determines all other attributes in the relation. Logical Implications - Suppose that A B and B C are FDs on a schema R=ABC. Then, A C is also an FD on R. Proof Let r(r) be a relation that satisfies FDs A B and B C. Suppose that t1, t2 r(r), such that t1[a] = t2[a] and t1[c] t2[c]. Dr. Byunggu Yu 4

If t1[b] t2[b] then A B does not hold. Otherwise, B C does not hold. By contradiction, we conclude that, for no two t1, t2 r(r), both t1[a]=t2[a] and t1[c] t2[c]. This is necessary and sufficient condition to uphold A C. - Let F be a set of FDs on R and let X Y be an FD on R which may or may not be in F. We say that F logically implies X Y, denoted by F =X Y, if every relation r(r) that satisfies FDs in F also satisfies X Y (i.e., for no two t1, t2 r(r), both t1[x]=t2[x] and t1[y] t2[y]). - Example: F={A B, B C} =A C Closure - Let F be a set of FDs on a schema R. The closure F + of the set F is the set of all FDs logically implied by F, i.e. F + = {X Y F = X Y} - Example: F = {A B, B C} F + = {A B, B C, A C, Dr. Byunggu Yu 5

AB C, ABC C, AB BC, BC B, A, B, C,...} These are commonly ignored Candidate Key - Let r(r=a1a2...an) be a relation for which the set of FDs F is satisfied. Let X R. We say that X is a candidate key for r(r) if 1. X A1A2...An F + 2. For no Y X, Y A1A2...An F + - X is a superkey if only 1 is satisfied. - But how can we check the condition 1? Use X + computation or Armstrong Axioms Closure of a set of attributes - Let X be a set of attributes s.t. X R and let F be a set of FDs on R. The closure of X under F, denoted by X +, is the set of all the attributes that are determined by X under F, i.e. X + = {A X A} X + Computation Complexity of the algorithm is proportional to the cardinality of the set of FDs, F. Algorithm: Input: A relation schema R, set of FDs F, and an attribute set X R. Dr. Byunggu Yu 6

Output: X +, i.e. the closure of X under F. Method: begin 1. X (0) =X 2. X (i+1) =X (i) {A Y,Z (Y Z F A Z Y X (i) )} 3. repeat step 2 until no more changes end Example 1 of 2: - F = {AB C, C A, BC D, ACD B, D EG, BE C, CG BD, CE AG} - X = BD - begin. X (0) =BD X (1) =BD {EG D EG} = BDEG X (2) =BDEG {C BE C} = BCDEG X (3) =BCDEG {ABDG CE AG,CG BD,BC D,C A} X (4) =ABCDEG {ABCDEG...} = ABCDEG X (4) = X (3) end! - X + = BD + = ABCDEG Example 2 of 2 - F = {A C, B DC, AC B}. Is A BD? - X=A - begin. X (0) =A X (1) =AC X (2) =ABC X (3) =ABCD Dr. Byunggu Yu 7

X (4) =ABCD X (4) =X (3) end! - X + = A + = ABCD ==> BD A + ==> A BD. Armstrong Axioms Sound and complete set of rules for the derivation of FDs in F +, given a set of FDs F. Primary axioms - Let R be a set of attributes, and let F be the set of FDs on R. Dr. Byunggu Yu 8

A1. Reflexivity: If Y X R, then F A1 = X Y (trivial FDs). A2. Additivity: X Y A 2 = XZ YZ for every Z R. A3. Transitivity: {X Y, Y Z} A 3 = X Z for X,Y,Z R. - Example: address (STREET, CITY, ZIP) F={ZIP CITY, {STREET,CITY} ZIP} Prove that {ZIP,STREET} is a superkey of the relation "address"! 1. ZIP CITY (given) 2. {ZIP,STREET} {STREET,CITY} (A2. additivity) 3. {STREET,CITY} ZIP (given) 4. {STREET,CITY} {STREET,CITY,ZIP} (A2. additivity) 5. {ZIP,STREET} {STREET,CITY,ZIP} (A3. transitivity from 2 and 4) ==> {ZIP,STREET} is a superkey. Secondary axioms - Can be derived from the primary axioms A4. Union: {X Y, X Z} A 4 = X YZ. A5. Pseudotransitivity: {X Y, WY Z} A 5 = WX Z. A6. Decomposition: If X Y and Z Y, then X Z. Dr. Byunggu Yu 9

- The derivation of the secondary rules: A4. F={X Y, X Z} (given) 1. X Y A = 2 X XY 2. X Z A = 2 XY YZ 3. {X XY, XY YZ} A 3 = X YZ A5. F={X Y, WY Z} (given) 1. X Y A = 2 WX WY 3. {WX WY, WY Z} A 3 = WX Z A6. F={X Y}, Z Y (given) 1. Z Y A1 = Y Z 3. {X Y, Y Z} A 3 = X Z - Important consequence of A4 and A6: X A1A2...An iff X Ai, i= 1, n. - To prove that X R is a superkey of a relation r(r), it is sufficient to show that Ai R, X Ai. Properties - Soundness: The axioms do not generate any incorrect FD, i.e. if X Y can be logically derived from F by Armstrong rules, then X Y holds. - Completeness: The axioms allow us to find all FDs in F+. Dr. Byunggu Yu 10

Examples: r(abc), F={AB C, C B} - Prove AC A A AC A1 = AC A - Prove AC B 1. C B (given) 2. AC AB (A2) 3. AC B (A6) - Prove AB ABC 1. AB C (given) 2. AB ABC (A2) - Prove AB BC 1. AB C (given) 2. AB BC (A2) Dr. Byunggu Yu 11