Top Banner
Multivalued Multivalued Dependency Dependency Tamer Abuelata Tamer Abuelata
21

Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Multivalued Multivalued DependencyDependency

Tamer AbuelataTamer Abuelata

Page 2: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

IntroductionIntroduction

Goal in Databases:Goal in Databases: BCNF (Boyce Codd Normal Form)BCNF (Boyce Codd Normal Form) LosslessnessLosslessness Dependency preservationDependency preservation

Page 3: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Remember…Remember…

Boyce Codd Normal Form (BCNF) Boyce Codd Normal Form (BCNF) eliminates all redundancy that can eliminates all redundancy that can be discovered based on functional be discovered based on functional dependencies.dependencies.

Page 4: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

IssueIssue

Some relation schemas, even though Some relation schemas, even though they are in BCNF, do not seem to be they are in BCNF, do not seem to be sufficiently normalized.sufficiently normalized.

They still contain They still contain repetitionsrepetitions

Page 5: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Case studyCase study

Consider the bank database schema:Consider the bank database schema:cust_loan = (cust_loan = (loan_number, cust_idloan_number, cust_id, cust_name, cust_street, cust_city), cust_name, cust_street, cust_city)

This is BCNF because of the functional This is BCNF because of the functional dependency:dependency:

cust_id -> cust_name, cust_street cust_citycust_id -> cust_name, cust_street cust_city

And because cust_id is not a key for And because cust_id is not a key for cust_loancust_loan

Page 6: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Case StudyCase Study

But what if some customers have But what if some customers have several addresses?several addresses?

We no longer wish to enforce the func. We no longer wish to enforce the func. dependency: dependency: cust_id ->cust_street cust_citycust_id ->cust_street cust_city

But we still want to enforceBut we still want to enforcecust_id -> cust_namecust_id -> cust_name

Page 7: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Case StudyCase Study

Following BCNF decomposition Following BCNF decomposition algorithmalgorithm

we get:we get:R1 = (R1 = (cust_idcust_id, cust_name), cust_name)

R2 = (R2 = (loan_number, cust_idloan_number, cust_id, cust_street, cust_city), cust_street, cust_city)

(both in BCNF)(both in BCNF)

Page 8: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Case StudyCase Study

The issueThe issue

Despite R2 in BCNF, there is Despite R2 in BCNF, there is redundancy. We repeat the address redundancy. We repeat the address of each residence for each loan that of each residence for each loan that the customer has.the customer has.

Page 9: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Case StudyCase Study

We can therefore We can therefore decompose decompose furtherfurther into: into:loan_cust_id = (loan_number, cust_id)loan_cust_id = (loan_number, cust_id)

cust_residence = (cust_id, cust_street, cust_city)cust_residence = (cust_id, cust_street, cust_city)

But there is no constraint that lead But there is no constraint that lead us to do that.us to do that.

To deal with this, we need a few To deal with this, we need a few form of constraint: 4NF.form of constraint: 4NF.

Page 10: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

4NF4NF

We can use multivalued We can use multivalued dependencies to define the dependencies to define the fourth fourth normal formnormal form

Page 11: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

4NF4NF

A relation schema R is in fourth A relation schema R is in fourth normal form with respect to a set D of normal form with respect to a set D of functional and multivalued functional and multivalued dependencies if, for all multivlued dependencies if, for all multivlued dependencies in D+ of the form A -->-dependencies in D+ of the form A -->-> B at least one of the following holds:> B at least one of the following holds: A -->-> B is a trivial multivalued A -->-> B is a trivial multivalued

dependencydependency A is a superkey for schema RA is a superkey for schema R

Page 12: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

Multivalued DependencyMultivalued Dependency

Requires that other tuples of a Requires that other tuples of a certain form be present in the certain form be present in the relation.relation.

Also referred to as:Also referred to as:

tuple-generating dependencytuple-generating dependency

Page 13: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

R relation schema, A and B follow the R relation schema, A and B follow the multivaluedmultivalued dependencydependency::

A A -->->-->-> B B

The relationship between A and B is The relationship between A and B is independent of the relation between A independent of the relation between A and R – Band R – B

If If A A -->-> -->-> B B is satisfied by all relations on R is satisfied by all relations on R thenthen

A A -->-> -->-> B B is a trivial multivalued dependencyis a trivial multivalued dependency

Page 14: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

Let’s reconsiderLet’s reconsiderR2 = (R2 = (loan_number, cust_idloan_number, cust_id, cust_street, cust_city), cust_street, cust_city)

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-23L-23 99-12399-123 MainMain ManchesterManchester

L-93L-93 15-10615-106 LakeLake HorseneckHorseneck

Page 15: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-23L-23 99-12399-123 MainMain ManchesterManchester

L-93L-93 15-10615-106 LakeLake HorseneckHorseneck

We must We must repeat the loan numberrepeat the loan number once for once for each addresseach address a customer has a customer has and we must and we must repeat the addressrepeat the address for for each loaneach loan a customer has. a customer has.

Page 16: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-23L-23 99-12399-123 MainMain ManchesterManchester

L-93L-93 15-10615-106 LakeLake HorseneckHorseneck

We must We must repeat the loan numberrepeat the loan number once for once for each addresseach address a customer has a customer has and we must and we must repeat the addressrepeat the address for for each loaneach loan a customer has. a customer has.This repetition is unnecessary since the This repetition is unnecessary since the relationship between a customer and his relationship between a customer and his address is independent of the relationship address is independent of the relationship between that customer and a loan.between that customer and a loan.

Page 17: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

Therefore this relation is Therefore this relation is illegalillegal

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-27L-27 99-12399-123 MainMain ManchesterManchester

Page 18: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

Therefore this relation is Therefore this relation is illegalillegal

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-27L-27 99-12399-123 MainMain ManchesterManchester

To make it legal we should add tuplesTo make it legal we should add tuples

(L23, 99-123, Main, Manchester) and(L23, 99-123, Main, Manchester) and

(L27, 99-123, North, Rye)(L27, 99-123, North, Rye)

Page 19: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-27L-27 99-12399-123 MainMain ManchesterManchester

L-23L-23 99-12399-123 MainMain ManchesterManchester

L-27L-27 99-12399-123 NorthNorth RyeRye

Updated table (legal)Updated table (legal)

Page 20: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ExampleExample

loan_numberloan_number cust_idcust_id cust_streetcust_street cust_citycust_city

L-23L-23 99-12399-123 NorthNorth RyeRye

L-27L-27 99-12399-123 MainMain ManchesterManchester

L-23L-23 99-12399-123 MainMain ManchesterManchester

L-27L-27 99-12399-123 NorthNorth RyeRye

Updated table (legal)Updated table (legal)

We wantWe want Cust_id Cust_id -->->-->-> cust_street cust_city cust_street cust_city

to holdto hold

Page 21: Multivalued Dependency Tamer Abuelata. Introduction Goal in Databases: Goal in Databases: BCNF (Boyce Codd Normal Form) BCNF (Boyce Codd Normal Form)

ConclusionConclusion

We can use multivalued We can use multivalued dependenciesdependencies

To test relations to determine To test relations to determine whether they are legal under a given whether they are legal under a given set of functional and multivalued set of functional and multivalued dependenciesdependencies

To specify constraints on the set of To specify constraints on the set of legal relationslegal relations