Functional Dependencies



Similar documents
Chapter 7: Relational Database Design

Boyce-Codd Normal Form

Chapter 7: Relational Database Design

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Database Design and Normalization

Relational Database Design: FD s & BCNF

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

Design of Relational Database Schemas

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Theory of Relational Database Design and Normalization

Functional Dependencies and Finding a Minimal Cover

Schema Refinement and Normalization

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

Schema Refinement, Functional Dependencies, Normalization

Chapter 10. Functional Dependencies and Normalization for Relational Databases

Relational Database Design

Theory of Relational Database Design and Normalization

Fundamentals of Database System

Relational Database Design Theory

Week 11: Normal Forms. Logical Database Design. Normal Forms and Normalization. Examples of Redundancy

COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Limitations of DB Design Processes

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Database Design and Normal Forms

Database Management System

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

We know how to query a database using SQL. A set of tables and their schemas are given Data are properly loaded

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

DATABASE NORMALIZATION

normalisation Goals: Suppose we have a db scheme: is it good? define precise notions of the qualities of a relational database scheme

CS143 Notes: Normalization Theory

Database Management Systems. Redundancy and Other Problems. Redundancy

Database Constraints and Design

Theory behind Normalization & DB Design. Satisfiability: Does an FD hold? Lecture 12

Normalisation to 3NF. Database Systems Lecture 11 Natasha Alechina

Normalization in Database Design

Functional Dependencies and Normalization

Lecture Notes on Database Normalization

Database Systems Concepts, Languages and Architectures

MCQs~Databases~Relational Model and Normalization

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

Introduction to SQL ( )

Chapter 5: FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL DATABASES

Introduction to Database Systems. Normalization

Advanced Relational Database Design

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Overview - detailed. Goal. Faloutsos CMU SCS

Functional Dependency and Normalization for Relational Databases

Chapter 8. Database Design II: Relational Normalization Theory

Design Theory for Relational Databases: Functional Dependencies and Normalization

Normalization. CIS 331: Introduction to Database Systems

Introduction to Database Systems. Chapter 4 Normal Forms in the Relational Model. Chapter 4 Normal Forms

Normalization in OODB Design

Chapter 6: Integrity Constraints

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

Introduction Decomposition Simple Synthesis Bernstein Synthesis and Beyond. 6. Normalization. Stéphane Bressan. January 28, 2015

SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Objectives of Database Design Functional Dependencies 1st Normal Form Decomposition Boyce-Codd Normal Form 3rd Normal Form Multivalue Dependencies

Theory I: Database Foundations

ER modelling, Weak Entities, Class Hierarchies, Aggregation

Normalization of database model. Pazmany Peter Catholic University 2005 Zoltan Fodroczi

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

Introduction to normalization. Introduction to normalization

Determination of the normalization level of database schemas through equivalence classes of attributes

Chapter 10. Functional Dependencies and Normalization for Relational Databases. Copyright 2007 Ramez Elmasri and Shamkant B.

A Web-Based Environment for Learning Normalization of Relational Database Schemata

B2.2-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

Comp 5311 Database Management Systems. 3. Structured Query Language 1

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Simple SQL Queries (3)

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 5: Normalization II; Database design case studies. September 26, 2005

RELATIONAL DATABASE DESIGN

The University of British Columbia

Objectives, outcomes, and key concepts. Objectives: give an overview of the normal forms and their benefits and problems.

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Normalisation. Why normalise? To improve (simplify) database design in order to. Avoid update problems Avoid redundancy Simplify update operations

Normalization of Database

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Normal forms and normalization

Lesson 8: Introduction to Databases E-R Data Modeling

Normalization. Normalization. Normalization. Data Redundancy

The class slides, your notes, and the sample problem that we worked in class may be helpful for reference.

Relational Normalization Theory (supplemental material)

An Algorithmic Approach to Database Normalization

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

Database Design and Normalization

Lecture 2 Normalization

Advance DBMS. Structured Query Language (SQL)

Question 1. Relational Data Model [17 marks] Question 2. SQL and Relational Algebra [31 marks]

Jordan University of Science & Technology Computer Science Department CS 728: Advanced Database Systems Midterm Exam First 2009/2010

Normalization. CIS 3730 Designing and Managing Data. J.G. Zheng Fall 2010

BCA. Database Management System

DATABASE SYSTEMS. Chapter 7 Normalisation

Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation

Quiz 3: Database Systems I Instructor: Hassan Khosravi Spring 2012 CMPT 354

Comp 3311 Database Management Systems. 2. Relational Model Exercises

Normalisation and Data Storage Devices

Topic 5.1: Database Tables and Normalization

Derivation of Database Keys Operations. Abstract. Introduction

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Transcription:

BCNF and 3NF

Functional Dependencies Functional dependencies: modeling constraints on attributes stud-id name address course-id session-id classroom instructor Functional dependencies should be obtained from application requirement analysis Functional dependencies should be maintained for all legal relations in the application CMPT 354: Database I -- BCNF and 3NF 2

Closure of Functional Dependencies A set of functional dependencies may logically imply other functional dependencies If A B and B C, then A C The set of all functional dependencies logically implied by F is the closure of F We denote the closure of F by F + F + is a superset of F CMPT 354: Database I -- BCNF and 3NF 3

Armstrong s Axioms Finding F + (reflexivity) If β α, then α β (augmentation) If α β, then γ α γβ (transitivity) If α β, and β γ, then α γ These rules are Sound: generate only functional dependencies that actually hold Complete: generate all functional dependencies that hold CMPT 354: Database I -- BCNF and 3NF 4

Computing Closure 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 CMPT 354: Database I -- BCNF and 3NF 5

Problem of Non-Key Dependencies bor_loan(customer_id, loan_number, amount) loan_number amount, but loan_number customer_id does not hold The amount information repeats unnecessarily Is loan_number also redundant? CMPT 354: Database I -- BCNF and 3NF 6

Update and Deletion Anomalies bor_loan(customer_id, loan_number, amount) Update anomalies: if the amount of a loan is changed and the loan has n customers, the n tuples have to be updated Deletion anomalies: if a loan having n customers is deleted, we have to delete n tuples The amount information has to be deleted n times Failing to update/delete all tuple leads to inconsistency CMPT 354: Database I -- BCNF and 3NF 7

Reducing Redundancy Make a table loan(loan_number, amount) where loan_number is the key Rename bor_loan to borrower(customer_id, loan_number) where (customer_id, loan_number) is the key No information loss by joining on loan_number Update/deletion anomalies are eliminated CMPT 354: Database I -- BCNF and 3NF 8

Boyce-Codd Normal Form A relation schema R is in BCNF if for all functional dependencies in F + of the form α β at least one of the following holds α β is trivial (i.e., β α) α is a superkey for R bor_loan = (customer_id, loan_number, amount) is not in BCNF loan_number amount holds on bor_loan but loan_number is not a superkey CMPT 354: Database I -- BCNF and 3NF 9

Decomposing into BCNF For schema R and a non-trivial dependency α β causes a violation of BCNF, decompose R into (α U β ): α is the key (R -( β - α )) bor_loan = (customer_id, loan_number, amount), loan_number amount (loan_number, amount ) (customer_id, loan_number) CMPT 354: Database I -- BCNF and 3NF 10

Missing Functional Dependencies cust_banker_branch(customer_id, employee_id, branch_name, type) R1: employee_id branch_name R2: customer_id, branch_name employee_id Not in BCNF, decompose into banker_branch(employee_id, branch_name) cust_banker(customer_id, employee_id, type) Functional dependency R2 is lost CMPT 354: Database I -- BCNF and 3NF 11

Insertion Anomalies Decompose cust_banker_branch(customer_id, employee_id, branch_name, type) into banker_branch(employee_id, branch_name) and cust_banker(customer_id, employee_id, type) Cannot insert (c1, e1, Burnaby, loan) and (c1, e2, Burnaby, loan) into cust_banker_branch R2: customer_id, branch_name employee_id is violated CMPT 354: Database I -- BCNF and 3NF 12

Insertion Anomalies Decompose cust_banker_branch(customer_id, employee_id, branch_name, type) into banker_branch(employee_id, branch_name) and cust_banker(customer_id, employee_id, type) Can insert (e1, Burnaby) (e2, Burnaby) into banker_branch, and (c1, e1, loan) and (c1, e2, loan) into cust_banker (c1, e1, Burnaby, loan) and (c1, e2, Burnaby, loan) are inserted into the join of banker_branch and cust_banker CMPT 354: Database I -- BCNF and 3NF 13

BCNF and Insertion Anomalies Decomposition to BCNF may lose some functional dependencies The lost functional dependencies lead to insertion anomalies CMPT 354: Database I -- BCNF and 3NF 14

BCNF and Dependency Preservation If it is sufficient to test only those dependencies on each individual relation of a decomposition in order to ensure that all functional dependencies hold, then that decomposition is dependency preserving Constraints, including functional dependencies, are costly to check in practice unless they pertain to only one relation joining multiple tables is costly BCNF may not preserve functional dependencies Consider a weaker normal form if functional dependencies cannot be preserved in BCNF CMPT 354: Database I -- BCNF and 3NF 15

Decomposition for Preservation Banker-info-schema = (branch-name, customername, banker-name, office-number) R1:banker-name branch-name office-number R2:customer-name branch-name banker-name Decomposition preserving all functional dependencies Banker-office-schema = (banker-name, branch-name, office-number), preserving R1 Banker-schema = (customer-name, branch-name, banker-name), preserving R2 (banker-name, branch-name) is repeated in both tables CMPT 354: Database I -- BCNF and 3NF 16

Third Normal Form A relation schema R is in the third normal form (3NF) if for all α β in F + at least one of the following holds α β is trivial (i.e., β α) α is a superkey for R Each attribute A in β α is contained in a candidate key for R Each attribute may be in a different candidate key If a relation is in BCNF it is in 3NF In BCNF one of the first two conditions above must hold The third condition is a minimal relaxation of BCNF to ensure dependency preservation CMPT 354: Database I -- BCNF and 3NF 17

Comparison of BCNF and 3NF It is always possible to decompose a relation into a set of relations that are in 3NF such that the decomposition is lossless and the dependencies are preserved It is always possible to decompose a relation into a set of relations that are in BCNF such that the decomposition is lossless It may not be possible to preserve all functional dependencies CMPT 354: Database I -- BCNF and 3NF 18

Design Goals Goal for a relational database design is BCNF Lossless join Dependency preservation If we cannot achieve all, we have to trade off between Lack of dependency preservation Redundancy due to use of 3NF CMPT 354: Database I -- BCNF and 3NF 19

Functional Dependencies and SQL SQL does not provide a direct way of specifying functional dependencies other than superkeys Can specify FDs using assertions, but they are expensive to test Even if we had a dependency preserving decomposition, using SQL we would not be able to efficiently test a functional dependency whose left hand side is not a key CMPT 354: Database I -- BCNF and 3NF 20

Summary Non-key dependencies causes redundancy and anomalies BCNF lossless decomposition, but may not preserve all functional dependencies 3NF lossless decomposition preserving all functional dependencies, but may still contain some redundancy CMPT 354: Database I -- BCNF and 3NF 21

To-Do-List Read Section 7.3 in the textbook Given a relation R, a set of functional dependencies F, and a decomposition of R how can we determine whether the decomposition is in BCNF? How can we determine whether the decomposition is in 3NF? CMPT 354: Database I -- BCNF and 3NF 22