INF1383 -Bancos de Dados

Size: px
Start display at page:

Download "INF1383 -Bancos de Dados"

Transcription

1 INF1383 -Bancos de Dados Prof. Sérgio Lifschitz DI PUC-Rio Eng. Computação, Sistemas de Informação e Ciência da Computação Projeto de BD e Formas Normais Alguns slides são baseados ou modificados dos originais dos livros Elmasri and Navathe, Fundamentals of Database Systems Pearson Education, Inc. e Database System Concepts, McGraw Hill Silberschatz, Korth and Sudarshan Slide 1 Relational Database Design Finding database schemes with good properties Example: Database for information on suppliers, parts supplied, and shipments Information consists of: S#: supplier number SNAME: supplier name SCITY: supplier city P#: part number PNAME: part name PCITY: city where part is stored QTY: quantity of shipment Slide 2

2 Relational Database Design One possible database schema BAD [S#, SNAME, SCITY, P#, PNAME, PCITY, QTY] Why BAD is bad: redundancy SCITY is determined by S# However, the same SCITY could appear many times with the same S# in this relation Functional dependency: S# SCITY update anomalies SCITY could be changed in one place but not in another, for the same S#, resulting in inconsistency Slide 3 Relational Database Design Why BAD is bad: insertion anomalies cannot record supplier info unless that supplier supplies a part deletion anomalies by deleting parts we can lose supplier info Solution New schema: S[S#, SNAME, SCITY] Key: S# P[P#, PNAME, PCITY] Key: P# SP[S#, P#, QTY] Key: S# P# No other functional dependencies besides key dependencies Normal forms: nice forms for schemas Slide 4

3 Decomposing Relation Schemes Let R be a relation scheme A decomposition of R is a set ρ={r 1,, R k } of relation schemes such that: att(r) = k i = 1 att(r i ) Example {S, P, SP} is a decomposition of the relation schema BAD (see earlier example) Slide 5 Conditions for a Reasonable Decomposition Do S, P, SP contain the same info as BAD? BAD = π S (BAD) >< π P (BAD) >< π SP (BAD)? Dependencies for BAD can be enforced by local dependencies on S, P, SP? Let F be the set of FDs for BAD F + denotes the set of FDs implied by F π X (F + ) = {V W F + VW X} Is π S (F + ) π P (F + ) π SP (F + ) equivalent to F? Slide 6

4 Functional-Dependency Theory We now consider the formal theory that tells us which functional dependencies are implied logically by a given set of functional dependencies. We then develop algorithms to generate lossless decompositions into BCNF and 3NF We then develop algorithms to test if a decomposition is dependency-preserving Slide 7 Functional Dependencies Functional dependency over R: expression X Y where X, Y att(r) A relation R satisfies X Y iff whenever two tuples in R agree on X, they also agree on Y e.g. SCHEDULE THEATER TITLE Roxy Artplex Tropa Rambo Satisfies THEATER TITLE SCHEDULE THEATER TITLE Roxy Tropa Artplex Rambo Artplex Platoon Violates THEATER TITLE, satisfies TITLE THEATER 8 Slide 8

5 Lossless-join Decomposition For the case of R = (R 1, R 2 ), we require that for all possible relations r on schema R r = R1 (r ) R2 (r ) A decomposition of R into R 1 and R 2 is lossless join if and only if at least one of the following dependencies is in F + : R 1 R 2 R 1 R 1 R 2 R 2 Slide 9 Dependency Preservation Let F i be the set of dependencies F + that include only attributes in R i. A decomposition is dependency preserving, if (F 1 F 2 F n ) + = F + If it is not, then checking updates for violation of functional dependencies may require computing joins, which is expensive. Slide 10

6 Technical Problem Checking if X A is implied by a set F of fds (F = X A) Notation: F + = {X Y F = X Y} Needed to compute keys and check satisfaction of BCNF and other normal forms. Solution: closure of a set of attributes wrt F: X + X + = {A F = X A} (all attributes determined by X) So, X A F + iff A X + 11 Slide 11 Example of Closure Computation R = ABCDEF F = {A C, BC D AD E} X = AB X (0) = AB X (1) = ABC X (2) = ABCD X (3) = ABCDE X (4) = X (3) X + = ABCDE To check if X is key in R: X + = R A A o B o A o B o C o A B C D o o o o B C D o o o o E o 12 Slide 12

7 Computing the closure of a set of attributes wrt a set of fd s Let F be a set of fd s over R, and x R. The following computes the closure x + of x wrt FL 1. X (0) X 2. X (i+1) X (i) {Z V Z F, V X (i) } We get: X (0) X (1) X (i) X (i+1) att(r) Since att(r) is finite, there must exist a k 0 such that X (k) = X (k+1) (and thus, X (j) = X (k) j k). Then, X + = X (k) Slide 13 Dependency Preserving Decompositions Notation: if F is a set of fd s over R and X R then π X (F + ) = {V W F + VW X}. these are the fds that apply to the set of attributes X ( local to X) Definition: Let ρ = (R 1,, R k ) be a decomposition for R and F a set of fd s over R. Then ρ preserves F iff the set of local fds k i=1π Ri (F + ) is equivalent to F In other words, all fds in F are implied by k i=1π Ri (F + ) 14 Slide 14

8 Normal Forms Terminology: Let R be a relation schema and F a set of fd s over R. Key: X att(r) such that X att(r) F +. Minimal key: X att(r) s.t. X att(r) F + and there is no Y X such that Y att(r) F +. A att(r) is prime: A X where X is a minimal key A is non-prime: A is not a member of any minimal key. 15 Slide 15 Purpose of normal forms Eliminate problems of redundancy and anomalies. Normal forms: first, second, third, Boyce-Codd Boyce-Codd Normal Form (BCNF) A relation scheme R is in BCNF wrt a set of fd s F over R, iff whenever X A F + and A X, X is a key for R Only nontrivial dependencies are those induced by keys 16 Slide 16

9 Example BAD(S#, P#, SNAME, PNAME, SCITY, PCITY, QTY) not in BCNF wrt F = S# SNAME SCITY P# PNAME PCITY S# P# QTY S(S#, SCITY, SNAME) is in BCNF wrt S# SNAME SCITY P(P#, PCITY, PNAME) is in BCNF wrt P# PNAME PCITY SP(S# P# QTY) is in BCNF wrt S# P# QTY 17 Slide 17 Decomposition of a relation schema into BCNF relation schemas, with lossless join Any relation scheme has a decomposition into BCNF relation schemes, with lossless join not always dependency preserving Example R = CITY ZIP ST F = CITY ST ZIP, ZIP CITY R has no decomposition into BCNF schemas, which preserves F (CITY ST ZIP is never preserved) Slide 18

10 Algorithm to obtain a lossless join decomposition of a given R wrt F Start with ρ = {R} Apply recursively the following procedure: for each S in ρ not in BCNF, let X A F + be such that XA S, A X, X is not a key of S replace S by S 1 and S 2, where S 1 = XA S 2 = S A until all relation schemes are in BCNF Note S S 1 S 2 lossless join: X A F + X is a key for S 1 Slide 19 Note a) R R 1 R i R k Lossless join wrt F S i1 S i2 S im Lossless join (for R i ) wrt π Ri (F+) R 1 R R 2 R i-1 S i1 S im S i2 R k Lossless join wrt F b) If ρ is a lossless join decomposition of R wrt F and ρ ρ then ρ is a lossless join decomposition as well. Slide 20

11 Example R = C T H R S G C = course T = teacher H = hour R = room S = student G = grade F: C T HR C HT R CS G HS R only key: HS Slide 21 Example CTHRSG Key = HS, C T CS G, HR C, HS R, TH R key = CS CSG CS G CTHRS key = SH C T TH R HR C HS R CT key = C C T CHRS key = SH CH R HR C HS R CHR key = CH, CH R HR HR C CHS key = SH SH C Slide 22

12 Remarks (drawbacks) Decomposition is not unique CHRS could be decomposed into CHR and CHS or CHR and RHS The decomposition does not preserve TH R local fds: G = {CS G C T CH R HR C SH C} which does not imply TH R Slide 23 BCNF and Dependency Preservation It is not always possible to get a BCNF decomposition that is dependency preserving R = (J, K, L ) F = {JK L L K } Two candidate keys = JK and JL R is not in BCNF Any decomposition of R will fail to preserve JK L This implies that testing for JK L requires a join Slide 24

13 Efficiency Is there an efficient algorithm for BCNF decomposition? Most likely NO: It is NP-complete to decide whether a relation scheme R is in BCNF wrt a set of fd s. Any algorithm for BCNF is most likely exponential 25 Slide 25 3NF Problem with BCNF: Not every relation schema can be decomposed into BCNF relation schemas which preserve the dependencies and have lossless join. Third Normal Form A relation scheme R is in Third Normal Form wrt a set F of fd s over R, if whenever X A holds in R and A X then either X is a key or A is prime Weaker than BCNF 26 Slide 26

14 Third Normal Form: Motivation There are some situations where BCNF is not dependency preserving, and efficient checking for FD violation on updates is important Solution: define a weaker normal form, called Third Normal Form (3NF) Allows some redundancy (with resultant problems; we will see examples later) But functional dependencies can be checked on individual relations without computing a join. There is always a lossless-join, dependency-preserving decomposition into 3NF. Slide 27 Computing a 3NF decomposition Minimal covers A set F of fd s is minimal iff 1) X Y F Y is a single attribute 2) for no X A F is F {X A} equivalent to F (no fd can be removed from F) 3) if X A F then there is no proper subset Z of X such that F {X A} {Z A} is equivalent to F (attributes cannot be removed from fd s in F) Fact:. Every set of fd s is equivalent to some minimal set of fds (called a minimal cover). 28 Slide 28

15 Dependency preserving decompositions into Third Normal Form R a schema F minimal set of fd s over R ρ = {XA 1 A m X A i F} {B R B does not occur in F} Example R = CTHRSG (see earlier example) F = C T CS G HR C HS R (minimal) HT R Then ρ = {CT, HRC, HTR, CSG, HRS} Slide 29 3NF Decomposition Algorithm (Cont.) 3NF decomposition algorithm ensures: each relation schema R i is in 3NF decomposition is dependency preserving and lossless-join Slide 30

16 Formal Results Theorem. ρ preserves F and each R i in ρ is in 3NF wrt π Ri (F + ). To obtain decomposition that also has lossless join: add to ρ a set K where K is a minimal key for R unless there already is a piece in the decomposition whose attributes form a key for R Theorem ρ {K} is a 3NF decomposition which is dependency preserving and has lossless join. 31 Slide 31 Extraneous Attributes Consider a set F of FDs and the functional dependency α β in F. Attribute A is extraneous in α if A α and F logically implies (F {α β}) {(α A) β}. Attribute A is extraneous in β if A β and the set of functional dependencies (F {α β}) {α (β A)} logically implies F. Example: Given F = {A C, AB C } B is extraneous in AB C because {A C, AB C} logically implies A C (i.e. the result of dropping B from AB C). Example: Given F = {A C, AB CD} C is extraneous in AB CD since AB C can be inferred even after deleting C Slide 32

17 Testing if an Attribute is Extraneous Consider a set F of functional dependencies and the functional dependency α β in F. To test if attribute A α is extraneous in α 1. compute ({α} A) + using the dependencies in F 2. check that ({α} A) + contains A; if it does, A is extraneous To test if attribute A β is extraneous in β 1. compute α + using only the dependencies in F = (F {α β}) {α (β A)}, 2. check that α + contains A; if it does, A is extraneous Slide 33 Canonical (Minimal) Cover Sets of functional dependencies may have redundant dependencies that can be inferred from the others For example: A C is redundant in: {A B, B C} Parts of a functional dependency may be redundant E.g.: on RHS: {A B, B C, A CD} can be simplified to {A B, B C, A D} E.g.: on LHS: {A B, B C, AC D} can be simplified to {A B, B C, A D} Intuitively, a canonical cover of F is a minimal set of functional dependencies equivalent to F, having no redundant dependencies or redundant parts of dependencies Slide 34

18 Canonical (minimal) Cover A canonical cover for F is a set of dependencies F c such that F logically implies all dependencies in F c, and F c logically implies all dependencies in F, and No functional dependency in F c contains an extraneous attribute, and Each left side of functional dependency in F c is unique. To compute a canonical cover for F: repeat Use the union rule to replace any dependencies in F α 1 β 1 and α 1 β 2 with α 1 β 1 β 2 Find a functional dependency α β with an extraneous attribute either in α or in β If an extraneous attribute is found, delete it from α β until F does not change Note: Union rule may become applicable after some extraneous attributes have been deleted, so it has to be re-applied Slide 35 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 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 dependencies. Slide 36

19 Design Goals Goal for a relational database design is: BCNF. Lossless join. Dependency preservation. If we cannot achieve this, we accept one of Lack of dependency preservation Redundancy due to use of 3NF Interestingly, 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. Slide 37 A (simplified) overview of schema design 1. Choose attributes in R 2. Specify dependencies F (tool: Armstrong relations ) 3. Find a lossless-join, dependency preserving decomposition into Normal Form schemas BCNF, if possible 3NF, if not BCNF 38 Slide 38

CSE 132B Database Systems Applications

CSE 132B Database Systems Applications CSE 132B Database Systems Applications Alin Deutsch Database Design and Normal Forms Some slides are based or modified from originals by Sergio Lifschitz @ PUC Rio, Brazil and Victor Vianu @ CSE UCSD and

More information

Constraints: Functional Dependencies

Constraints: Functional Dependencies Constraints: Functional Dependencies Fall 2017 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Functional Dependencies 1 / 42 Schema Design When we get a relational

More information

Constraints: Functional Dependencies

Constraints: Functional Dependencies Constraints: Functional Dependencies Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Functional Dependencies 1 / 32 Schema Design When we get a relational

More information

Problem about anomalies

Problem about anomalies Problem about anomalies Title Year Genre StarName Star Wars 1977 SciFi Carrie Fisher Star Wars 1977 SciFi Harrison Ford Raiders... 1981 Action Harrison Ford Raiders... 1981 Adventure Harrison Ford When

More information

Database Design and Normalization

Database Design and Normalization Database Design and Normalization Chapter 11 (Week 12) EE562 Slides and Modified Slides from Database Management Systems, R. Ramakrishnan 1 1NF FIRST S# Status City P# Qty S1 20 London P1 300 S1 20 London

More information

Relational Database Design

Relational Database Design Relational Database Design Jan Chomicki University at Buffalo Jan Chomicki () Relational database design 1 / 16 Outline 1 Functional dependencies 2 Normal forms 3 Multivalued dependencies Jan Chomicki

More information

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

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties Review: Keys Superkey: set of attributes whose values are unique for each tuple Note: a superkey isn t necessarily minimal. For example, for any relation, the entire set of attributes is always a superkey.

More information

Chapter 7: Relational Database Design

Chapter 7: Relational Database Design Chapter 7: Relational Database Design Chapter 7: Relational Database Design! First Normal Form! Pitfalls in Relational Database Design! Functional Dependencies! Decomposition! Boyce-Codd Normal Form! Third

More information

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

COSC 430 Advanced Database Topics. Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago COSC 430 Advanced Database Topics Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago Learning objectives and references You should be able to: define the elements of the relational

More information

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

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies? Normalization Introduction What problems are caused by redundancy? UVic C SC 370 Dr. Daniel M. German Department of Computer Science What are functional dependencies? What are normal forms? What are the

More information

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

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design Chapter 7: Relational Database Design Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition Boyce-Codd Normal Form Third Normal

More information

CS54100: Database Systems

CS54100: Database Systems CS54100: Database Systems Keys and Dependencies 18 January 2012 Prof. Chris Clifton Functional Dependencies X A = assertion about a relation R that whenever two tuples agree on all the attributes of X,

More information

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

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information Relational Database Design Database Design To generate a set of relation schemas that allows - to store information without unnecessary redundancy - to retrieve desired information easily Approach - design

More information

Chapter 8: Relational Database Design

Chapter 8: Relational Database Design Chapter 8: Relational Database Design Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 8: Relational Database Design Features of Good Relational Design Atomic Domains

More information

Relational Database Design

Relational Database Design CSL 451 Introduction to Database Systems Relational Database Design Department of Computer Science and Engineering Indian Institute of Technology Ropar Narayanan (CK) Chatapuram Krishnan! Recap - Boyce-Codd

More information

Design Theory for Relational Databases

Design Theory for Relational Databases Design Theory for Relational Databases FUNCTIONAL DEPENDENCIES DECOMPOSITIONS NORMAL FORMS 1 Functional Dependencies X ->Y is an assertion about a relation R that whenever two tuples of R agree on all

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms UMass Amherst Feb 14, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke, Dan Suciu 1 Relational Schema Design Conceptual Design name Product buys Person price name

More information

SCHEMA NORMALIZATION. CS 564- Fall 2015

SCHEMA NORMALIZATION. CS 564- Fall 2015 SCHEMA NORMALIZATION CS 564- Fall 2015 HOW TO BUILD A DB APPLICATION Pick an application Figure out what to model (ER model) Output: ER diagram Transform the ER diagram to a relational schema Refine the

More information

Database Design and Implementation

Database Design and Implementation Database Design and Implementation CS 645 Schema Refinement First Normal Form (1NF) A schema is in 1NF if all tables are flat Student Name GPA Course Student Name GPA Alice 3.8 Bob 3.7 Carol 3.9 Alice

More information

Schema Refinement & Normalization Theory

Schema Refinement & Normalization Theory Schema Refinement & Normalization Theory Functional Dependencies Week 13 1 What s the Problem Consider relation obtained (call it SNLRHW) Hourly_Emps(ssn, name, lot, rating, hrly_wage, hrs_worked) What

More information

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

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016 Normal Forms Dr Paolo Guagliardo University of Edinburgh Fall 2016 Example of bad design BAD Title Director Theatre Address Time Price Inferno Ron Howard Vue Omni Centre 20:00 11.50 Inferno Ron Howard

More information

Databases 2012 Normalization

Databases 2012 Normalization Databases 2012 Christian S. Jensen Computer Science, Aarhus University Overview Review of redundancy anomalies and decomposition Boyce-Codd Normal Form Motivation for Third Normal Form Third Normal Form

More information

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

Schema Refinement and Normal Forms. Case Study: The Internet Shop. Redundant Storage! Yanlei Diao UMass Amherst November 1 & 6, 2007 Schema Refinement and Normal Forms Yanlei Diao UMass Amherst November 1 & 6, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Case Study: The Internet Shop DBDudes Inc.: a well-known database consulting

More information

Functional Dependency Theory II. Winter Lecture 21

Functional Dependency Theory II. Winter Lecture 21 Functional Dependency Theory II Winter 2006-2007 Lecture 21 Last Time Introduced Third Normal Form A weakened version of BCNF that preserves more functional dependencies Allows non-trivial dependencies

More information

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

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007 Schema Refinement and Normal Forms Yanlei Diao UMass Amherst April 10, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 The Evils of Redundancy Redundancy is at the root of several problems associated

More information

Lecture 6 Relational Database Design

Lecture 6 Relational Database Design Lecture 6 Relational Database Design Shuigeng Zhou October 21/27, 2009 School of Computer Science Fudan University Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional

More information

CS322: Database Systems Normalization

CS322: Database Systems Normalization CS322: Database Systems Normalization Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Introduction The normalization process takes a relation schema through

More information

Schema Refinement and Normal Forms Chapter 19

Schema Refinement and Normal Forms Chapter 19 Schema Refinement and Normal Forms Chapter 19 Instructor: Vladimir Zadorozhny vladimir@sis.pitt.edu Information Science Program School of Information Sciences, University of Pittsburgh Database Management

More information

CSC 261/461 Database Systems Lecture 11

CSC 261/461 Database Systems Lecture 11 CSC 261/461 Database Systems Lecture 11 Fall 2017 Announcement Read the textbook! Chapter 8: Will cover later; But self-study the chapter Everything except Section 8.4 Chapter 14: Section 14.1 14.5 Chapter

More information

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018 DESIGN THEORY FOR RELATIONAL DATABASES csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018 1 Introduction There are always many different schemas for a given

More information

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

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19 FUNCTIONAL DEPENDENCY THEORY CS121: Relational Databases Fall 2017 Lecture 19 Last Lecture 2 Normal forms specify good schema patterns First normal form (1NF): All attributes must be atomic Easy in relational

More information

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

Normalization. October 5, Chapter 19. CS445 Pacific University 1 10/05/17 Normalization October 5, 2017 Chapter 19 Pacific University 1 Description A Real Estate agent wants to track offers made on properties. Each customer has a first and last name. Each property has a size,

More information

Lossless Joins, Third Normal Form

Lossless Joins, Third Normal Form Lossless Joins, Third Normal Form FCDB 3.4 3.5 Dr. Chris Mayfield Department of Computer Science James Madison University Mar 19, 2018 Decomposition wish list 1. Eliminate redundancy and anomalies 2. Recover

More information

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

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram The Evils of Redundancy Schema Refinement and Normalization Chapter 1 Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus Redundancy is at the root of several problems

More information

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

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design Outline Introduction to Database Systems CSE 444 Design theory: 3.1-3.4 [Old edition: 3.4-3.6] Lectures 6-7: Database Design 1 2 Schema Refinements = Normal Forms 1st Normal Form = all tables are flat

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms Yanlei Diao UMass Amherst April 10 & 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Case Study: The Internet Shop DBDudes Inc.: a well-known database consulting

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms Chapter 19 Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke 1 The Evils of Redundancy Redundancy is at the root of several problems associated with relational

More information

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa ICS 321 Fall 2012 Normal Forms (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/12/2012 Lipyeow Lim -- University of Hawaii at Manoa 1 Hourly_Emps

More information

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

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1 Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1 Background We started with schema design ER model translation into a relational schema Then we studied relational

More information

Shuigeng Zhou. April 6/13, 2016 School of Computer Science Fudan University

Shuigeng Zhou. April 6/13, 2016 School of Computer Science Fudan University Lecture 6 Relational Database Design Shuigeng Zhou April 6/13, 2016 School of Computer Science Fudan University Relational Database Design p First Normal Form p Pitfalls in Relational Database Design p

More information

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh Functional Dependencies and Normalization Instructor: Mohamed Eltabakh meltabakh@cs.wpi.edu 1 Goal Given a database schema, how do you judge whether or not the design is good? How do you ensure it does

More information

CSC 261/461 Database Systems Lecture 13. Spring 2018

CSC 261/461 Database Systems Lecture 13. Spring 2018 CSC 261/461 Database Systems Lecture 13 Spring 2018 BCNF Decomposition Algorithm BCNFDecomp(R): Find X s.t.: X + X and X + [all attributes] if (not found) then Return R let Y = X + - X, Z = (X + ) C decompose

More information

Chapter 3 Design Theory for Relational Databases

Chapter 3 Design Theory for Relational Databases 1 Chapter 3 Design Theory for Relational Databases Contents Functional Dependencies Decompositions Normal Forms (BCNF, 3NF) Multivalued Dependencies (and 4NF) Reasoning About FD s + MVD s 2 Remember our

More information

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

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd. The Evils of Redundancy Schema Refinement and Normal Forms INFO 330, Fall 2006 1 Redundancy is at the root of several problems associated with relational schemas: redundant storage, insert/delete/update

More information

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li 1 Third Normal Form (3NF) v Relation R is in 3NF if it is in 2NF and it has no transitive dependencies

More information

Schema Refinement: Other Dependencies and Higher Normal Forms

Schema Refinement: Other Dependencies and Higher Normal Forms Schema Refinement: Other Dependencies and Higher Normal Forms Spring 2018 School of Computer Science University of Waterloo Databases CS348 (University of Waterloo) Higher Normal Forms 1 / 14 Outline 1

More information

Design Theory for Relational Databases

Design Theory for Relational Databases Design Theory for Relational Databases Keys: formal definition K is a superkey for relation R if K functionally determines all attributes of R K is a key for R if K is a superkey, but no proper subset

More information

Relational-Database Design

Relational-Database Design C H A P T E R 7 Relational-Database Design Exercises 7.2 Answer: A decomposition {R 1, R 2 } is a lossless-join decomposition if R 1 R 2 R 1 or R 1 R 2 R 2. Let R 1 =(A, B, C), R 2 =(A, D, E), and R 1

More information

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) Example (Contd. The Evils of Redundancy Schema Refinement and Normal Forms Chapter 19 Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke 1 Redundancy is at the root of several problems associated with relational

More information

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

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram Schema Refinement and Normal Forms Chapter 19 Database Management Systems, R. Ramakrishnan and J. Gehrke 1 The Evils of Redundancy Redundancy is at the root of several problems associated with relational

More information

Lectures 6. Lecture 6: Design Theory

Lectures 6. Lecture 6: Design Theory Lectures 6 Lecture 6: Design Theory Lecture 6 Announcements Solutions to PS1 are posted online. Grades coming soon! Project part 1 is out. Check your groups and let us know if you have any issues. We have

More information

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms Schema Refinement and Normal Forms Chapter 19 Quiz #2 Next Thursday Comp 521 Files and Databases Fall 2012 1 The Evils of Redundancy v Redundancy is at the root of several problems associated with relational

More information

Functional Dependencies and Normalization

Functional Dependencies and Normalization Functional Dependencies and Normalization There are many forms of constraints on relational database schemata other than key dependencies. Undoubtedly most important is the functional dependency. A functional

More information

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) [R&G] Chapter 19 Schema Refinement and Normal Forms [R&G] Chapter 19 CS432 1 The Evils of Redundancy Redundancy is at the root of several problems associated with relational schemas: redundant storage, insert/delete/update

More information

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status) So far we have seen: RECAP How to use functional dependencies to guide the design of relations How to modify/decompose relations to achieve 1NF, 2NF and 3NF relations But How do we make sure the decompositions

More information

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

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004 Schema Refinement and Normal Forms CIS 330, Spring 2004 Lecture 11 March 2, 2004 1 The Evils of Redundancy Redundancy is at the root of several problems associated with relational schemas: redundant storage,

More information

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

Introduction to Data Management. Lecture #6 (Relational DB Design Theory) Introduction to Data Management Lecture #6 (Relational DB Design Theory) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Homework

More information

Relational Design Theory

Relational Design Theory Relational Design Theory CSE462 Database Concepts Demian Lessa/Jan Chomicki Department of Computer Science and Engineering State University of New York, Buffalo Fall 2013 Overview How does one design a

More information

Functional Dependencies & Normalization. Dr. Bassam Hammo

Functional Dependencies & Normalization. Dr. Bassam Hammo Functional Dependencies & Normalization Dr. Bassam Hammo Redundancy and Normalisation Redundant Data Can be determined from other data in the database Leads to various problems INSERT anomalies UPDATE

More information

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

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi Design Theory for Relational Databases Spring 2011 Instructor: Hassan Khosravi Chapter 3: Design Theory for Relational Database 3.1 Functional Dependencies 3.2 Rules About Functional Dependencies 3.3 Design

More information

Schema Refinement and Normal Forms. Chapter 19

Schema Refinement and Normal Forms. Chapter 19 Schema Refinement and Normal Forms Chapter 19 1 Review: Database Design Requirements Analysis user needs; what must the database do? Conceptual Design high level descr. (often done w/er model) Logical

More information

Schema Refinement and Normal Forms. Why schema refinement?

Schema Refinement and Normal Forms. Why schema refinement? Schema Refinement and Normal Forms Why schema refinement? Consider relation obtained from Hourly_Emps: Hourly_Emps (sin,rating,hourly_wages,hourly_worked) Problems: Update Anomaly: Can we change the wages

More information

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018 CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018 Announcement Read Chapter 14 and 15 You must self-study these chapters Too huge to cover in Lectures Project 2 Part 1 due tonight Agenda 1.

More information

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

Introduction to Data Management. Lecture #7 (Relational DB Design Theory II) Introduction to Data Management Lecture #7 (Relational DB Design Theory II) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v Homework

More information

CSC 261/461 Database Systems Lecture 12. Spring 2018

CSC 261/461 Database Systems Lecture 12. Spring 2018 CSC 261/461 Database Systems Lecture 12 Spring 2018 Announcement Project 1 Milestone 2 due tonight! Read the textbook! Chapter 8: Will cover later; But self-study the chapter Chapter 14: Section 14.1 14.5

More information

Relational Design: Characteristics of Well-designed DB

Relational Design: Characteristics of Well-designed DB Relational Design: Characteristics of Well-designed DB 1. Minimal duplication Consider table newfaculty (Result of F aculty T each Course) Id Lname Off Bldg Phone Salary Numb Dept Lvl MaxSz 20000 Cotts

More information

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

Background: Functional Dependencies. æ We are always talking about a relation R, with a æxed schema èset of attributesè and a Background: Functional Dependencies We are always talking about a relation R, with a xed schema èset of attributesè and a varying instance èset of tuplesè. Conventions: A;B;:::are attributes; :::;Y;Z are

More information

CSC 261/461 Database Systems Lecture 8. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

CSC 261/461 Database Systems Lecture 8. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101 CSC 261/461 Database Systems Lecture 8 Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101 Agenda 1. Database Design 2. Normal forms & functional dependencies 3. Finding functional dependencies

More information

Schema Refinement and Normalization

Schema Refinement and Normalization Schema Refinement and Normalization Schema Refinements and FDs Redundancy is at the root of several problems associated with relational schemas. redundant storage, I/D/U anomalies Integrity constraints,

More information

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

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke Schema Refinement Yanlei Diao UMass Amherst Slides Courtesy of R. Ramakrishnan and J. Gehrke 1 Revisit a Previous Example ssn name Lot Employees rating hourly_wages hours_worked ISA contractid Hourly_Emps

More information

Database Normaliza/on. Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Database Normaliza/on. Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Database Normaliza/on Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata Problems with redundancy Data (attributes) being present in multiple tables Potential problems Increase of storage

More information

Functional Dependencies. Applied Databases. Not all designs are equally good! An example of the bad design

Functional Dependencies. Applied Databases. Not all designs are equally good! An example of the bad design Applied Databases Handout 2a. Functional Dependencies and Normal Forms 20 Oct 2008 Functional Dependencies This is the most mathematical part of the course. Functional dependencies provide an alternative

More information

Design theory for relational databases

Design theory for relational databases Design theory for relational databases 1. Consider a relation with schema R(A,B,C,D) and FD s AB C, C D and D A. a. What are all the nontrivial FD s that follow from the given FD s? You should restrict

More information

Information Systems (Informationssysteme)

Information Systems (Informationssysteme) Information Systems (Informationssysteme) Jens Teubner, TU Dortmund jens.teubner@cs.tu-dortmund.de Summer 2015 c Jens Teubner Information Systems Summer 2015 1 Part VII Schema Normalization c Jens Teubner

More information

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

FUNCTIONAL DEPENDENCY THEORY II. CS121: Relational Databases Fall 2018 Lecture 20 FUNCTIONAL DEPENDENCY THEORY II CS121: Relational Databases Fall 2018 Lecture 20 Canonical Cover 2 A canonical cover F c for F is a set of functional dependencies such that: F logically implies all dependencies

More information

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems Relational Database Design Theory Part II CPS 116 Introduction to Database Systems Announcements (October 12) 2 Midterm graded; sample solution available Please verify your grades on Blackboard Project

More information

CMPT 354: Database System I. Lecture 9. Design Theory

CMPT 354: Database System I. Lecture 9. Design Theory CMPT 354: Database System I Lecture 9. Design Theory 1 Design Theory Design theory is about how to represent your data to avoid anomalies. Design 1 Design 2 Student Course Room Mike 354 AQ3149 Mary 354

More information

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

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1 CAS CS 460/660 Introduction to Database Systems Functional Dependencies and Normal Forms 1.1 Review: Database Design Requirements Analysis user needs; what must database do? Conceptual Design high level

More information

CSIT5300: Advanced Database Systems

CSIT5300: Advanced Database Systems CSIT5300: Advanced Database Systems L05: Functional Dependencies Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China

More information

Chapter 3 Design Theory for Relational Databases

Chapter 3 Design Theory for Relational Databases 1 Chapter 3 Design Theory for Relational Databases Contents Functional Dependencies Decompositions Normal Forms (BCNF, 3NF) Multivalued Dependencies (and 4NF) Reasoning About FD s + MVD s 2 Our example

More information

CSE 344 AUGUST 6 TH LOSS AND VIEWS

CSE 344 AUGUST 6 TH LOSS AND VIEWS CSE 344 AUGUST 6 TH LOSS AND VIEWS ADMINISTRIVIA WQ6 due tonight HW7 due Wednesday DATABASE DESIGN PROCESS Conceptual Model: name product makes company price name address Relational Model: Tables + constraints

More information

Normal Forms Lossless Join.

Normal Forms Lossless Join. Normal Forms Lossless Join http://users.encs.concordia.ca/~m_oran/ 1 Types of Normal Forms A relation schema R is in the first normal form (1NF) if the domain of its each attribute has only atomic values

More information

Schema Refinement. Feb 4, 2010

Schema Refinement. Feb 4, 2010 Schema Refinement Feb 4, 2010 1 Relational Schema Design Conceptual Design name Product buys Person price name ssn ER Model Logical design Relational Schema plus Integrity Constraints Schema Refinement

More information

CS 186, Fall 2002, Lecture 6 R&G Chapter 15

CS 186, Fall 2002, Lecture 6 R&G Chapter 15 Schema Refinement and Normalization CS 186, Fall 2002, Lecture 6 R&G Chapter 15 Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus Functional Dependencies (Review)

More information

Normaliza)on and Func)onal Dependencies

Normaliza)on and Func)onal Dependencies Normaliza)on and Func)onal Dependencies 1NF and 2NF Redundancy and Anomalies Func)onal Dependencies A9ribute Closure Keys and Super keys 3NF BCNF Minimal Cover Algorithm 3NF Synthesis Algorithm Decomposi)on

More information

Lecture #7 (Relational Design Theory, cont d.)

Lecture #7 (Relational Design Theory, cont d.) Introduction to Data Management Lecture #7 (Relational Design Theory, cont d.) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements

More information

Functional Dependencies

Functional Dependencies Functional Dependencies Functional Dependencies Framework for systematic design and optimization of relational schemas Generalization over the notion of Keys Crucial in obtaining correct normalized schemas

More information

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

11/6/11. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design) Relational Schema Design Introduction to Management CSE 344 Lectures 16: Database Design Conceptual Model: Relational Model: plus FD s name Product buys Person price name ssn Normalization: Eliminates

More information

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

Introduction to Data Management. Lecture #6 (Relational Design Theory) Introduction to Data Management Lecture #6 (Relational Design Theory) Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Announcements v HW#2 is

More information

Practice and Applications of Data Management CMPSCI 345. Lecture 16: Schema Design and Normalization

Practice and Applications of Data Management CMPSCI 345. Lecture 16: Schema Design and Normalization Practice and Applications of Data Management CMPSCI 345 Lecture 16: Schema Design and Normalization Keys } A superkey is a set of a/ributes A 1,..., A n s.t. for any other a/ribute B, we have A 1,...,

More information

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

Functional. Dependencies. Functional Dependency. Definition. Motivation: Definition 11/12/2013 Functional Dependencies Functional Dependency Functional dependency describes the relationship between attributes in a relation. Eg. if A and B are attributes of relation R, B is functionally dependent

More information

DECOMPOSITION & SCHEMA NORMALIZATION

DECOMPOSITION & SCHEMA NORMALIZATION DECOMPOSITION & SCHEMA NORMALIZATION CS 564- Spring 2018 ACKs: Dan Suciu, Jignesh Patel, AnHai Doan WHAT IS THIS LECTURE ABOUT? Bad schemas lead to redundancy To correct bad schemas: decompose relations

More information

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

Introduction to Database Systems CSE 414. Lecture 20: Design Theory Introduction to Database Systems CSE 414 Lecture 20: Design Theory CSE 414 - Spring 2018 1 Class Overview Unit 1: Intro Unit 2: Relational Data Models and Query Languages Unit 3: Non-relational data Unit

More information

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

CSE 303: Database. Outline. Lecture 10. First Normal Form (1NF) First Normal Form (1NF) 10/1/2016. Chapter 3: Design Theory of Relational Database CSE 303: Database Lecture 10 Chapter 3: Design Theory of Relational Database Outline 1st Normal Form = all tables attributes are atomic 2nd Normal Form = obsolete Boyce Codd Normal Form = will study 3rd

More information

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Features of Good Relational Design! Atomic Domains and First Normal Form! Decomposition

More information

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

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design) Relational Schema Design Introduction to Management CSE 344 Lectures 16: Database Design Conceptual Model: Relational Model: plus FD s name Product buys Person price name ssn Normalization: Eliminates

More information

Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Normal Forms 1. ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa ICS 321 Fall 2013 Normal Forms 1 Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/16/2013 Lipyeow Lim -- University of Hawaii at Manoa 1 The Problem with

More information

Kapitel 3: Formal Design

Kapitel 3: Formal Design Theory I: Database Foundations 3. Formal Design 3. Kapitel 3: Formal Design We want to distinguish good from bad database design. What kind of additional information do we need? Can we transform a bad

More information

Functional Dependency and Algorithmic Decomposition

Functional Dependency and Algorithmic Decomposition Functional Dependency and Algorithmic Decomposition In this section we introduce some new mathematical concepts relating to functional dependency and, along the way, show their practical use in relational

More information

Relational Design Theory II. Detecting Anomalies. Normal Forms. Normalization

Relational Design Theory II. Detecting Anomalies. Normal Forms. Normalization Relational Design Theory II Normalization Detecting Anomalies SID Activity Fee Tax 1001 Piano $20 $2.00 1090 Swimming $15 $1.50 1001 Swimming $15 $1.50 Why is this bad design? Can we capture this using

More information