multivalued dependency

21
Multivalued Multivalued Dependency Dependency Tamer Abuelata Tamer Abuelata

Upload: avnis

Post on 21-May-2015

8.281 views

Category:

Business


2 download

TRANSCRIPT

Page 1: Multivalued dependency

Multivalued Multivalued DependencyDependency

Tamer AbuelataTamer Abuelata

Page 2: Multivalued dependency

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

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

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

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

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

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

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

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

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

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

Multivalued DependencyMultivalued Dependency

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

Multivalued Dependencies The The multivalued dependencymultivalued dependency relates  relates

to this problem when more than one to this problem when more than one multivalued attributes exist.multivalued attributes exist.

Also referred to as:Also referred to as:

tuple-generating dependencytuple-generating dependency

Page 13: Multivalued dependency

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

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

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

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

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

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 To make it legal we should add tuplestuples

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

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

Page 19: Multivalued dependency

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

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

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