multivalued dependency tamer abuelata. introduction goal in databases: goal in databases: bcnf...

21
Multivalued Multivalued Dependency Dependency Tamer Abuelata Tamer Abuelata

Post on 21-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Multivalued Multivalued DependencyDependency

Tamer AbuelataTamer Abuelata

IntroductionIntroduction

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

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.

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

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

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

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)

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.

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.

4NF4NF

We can use multivalued We can use multivalued dependencies to define the dependencies to define the fourth fourth normal formnormal 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

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

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

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

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.

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.

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

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)

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)

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

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