+ All Categories
Home > Documents > Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b...

Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b...

Date post: 12-Jan-2016
Category:
Upload: dustin-shields
View: 216 times
Download: 0 times
Share this document with a friend
20
NORMALIZATION AND TRANSFORMING AN ERD INTO RELATIONS
Transcript
Page 1: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

NORMALIZATION AND TRANSFORMING AN ERD INTO RELATIONS

Page 2: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Functional Dependence

An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value a for A (at a time).

b2

b3

a1

b1

Page 3: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Example: functional dependenceAll sales representatives in a given pay class have the same commission rate.

SalesRepNumber Name PayClass Commission

Page 4: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Normal Forms

A set of conditions on table structure that improves maintenance. Normalization removes processing anomalies: Update Inconsistent Data Addition Deletion

Page 5: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Normal Forms

All attributes depend on the key, the whole key and nothing but the key.

1NF Keys and no repeating groups2NF No partial dependencies3NF All determinants are candidate

keys4NF No multivalued dependencies

Page 6: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

6

EXAMPLEPLAYERID

POSITION

PLAYER_NAME

COACH

Coach City

01 Forward

Ronaldo Joe London

02 Midfield

Zidane Ed Madrid

03 Forward

Rooney Pete Manchester

04 Goal Cassilas Jim Barcelona

05 Forward

Fabregas Joe London

01 Midfield

Ronaldo Ed Madrid Player_id

CoachPosition

Player Name

City

Transitive Dependency

Partial Functional

Dependencies

Page 7: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

1st Normal Form Table has a primary key Table has no repeating groups Anomalies in 1st normal form

Inserting We cannot enter the fact that a player information

until his position is known Solved in 2nd Normal form Cannot Enter a Coach and City information with an

assigned player and position Solved in 3rd Normal Form

Deleting If we Delete Player id 03 we loose information about

coach “Pete” . Solved in 3rd Normal Form Updating

If coach Joe moves from London to Amsterdam,we have to search for all relevant tuples and update them Will be solved in 3rd Normal Form

Page 8: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

8

Second Normal Form A relation R is in 2 NF if and only if it is in 1NF and every

non-key attribute is fully dependent on the primary key Partial functional dependency: one or more non-key

attributes are functionally dependent on part of the primary key

PLAYERID

Player Name

01 Ronaldo

02 Zidane

03 Rooney

04 Cassilas

05 Fabregas

PLAYERID

POSITION

COACH

Coach City

01 Forward Joe London

02 Midfield Ed Madrid

03 Forward Pete Manchester

04 Goal Jim Barcelona

05 Forward Joe London

01 Midfield Ed Madrid

Page 9: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

9

Anomalies (2 NF) Inserting

We cannot insert Coach and City Information unless Player id and Position is identified.

Deleting If we Delete Player id 03 we loose

information about coach “Pete” . Updating

If coach Joe moves from London to Amsterdam,we have to search for all relevant tuples and update them Will be solved in 3rd Normal Form

Page 10: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

10

Third Normal Form A relation is in 3 NF if and only if it is in 2 NF and every non-

key attribute is non-transitively dependent on the primary key Transitive Dependency: functional dependency between two

or more non-key attributes in a relation

PLAYERID

Player Name

01 Ronaldo

02 Zidane

03 Rooney

04 Cassilas

05 Fabregas

PLAYERID

POSITION

COACH

01 Forward Joe

02 Midfield Ed

03 Forward Pete

04 Goal Jim

05 Forward Joe

01 Midfield Ed

Coach Coach City

Joe London

Ed Madrid

Pete Manchester

Jim Barcelona

Page 11: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Normalization1NF Keys & no repeating groups2NF 1NF & all attributes depend on

all key components3NF 2NF & all determinants are

candidate keys

Pros: Improves maintenance for database changes

Cons: Tends to slow down retrieval

Page 12: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations

Foreign Key An attribute that appears as a nonprimary

key attribute in one relation and as a primary key attribute (or part of a primary key) in another relation

Referential Integrity An integrity constraint specifying that the

value (or existence) of an attribute in one relation depends on the value (or existence) of the same attribute in another relation

9.129.12

Page 13: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations (Continued) It is useful to transform the

conceptual data model into a set of normalized relations

Steps:1. Represent entities2. Represent relationships3. Normalize the relations4. Create Tables

9.139.13

Page 14: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations (continued)

1. Represent Entities Each regular entity is transformed into a

relation The identifier of the entity type becomes

the primary key of the corresponding relation

The primary key must satisfy the following two conditionsa. The value of the key must uniquely identify

every row in the relationb. The key should be non-redundant

9.149.14

Page 15: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

9.159.15

Page 16: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations (continued)

2. Represent Relationships Binary 1:N Relationships

Add the primary key attribute (or attributes) of the entity on the one side of the relationship as a foreign key in the relation on the right side

The one side migrates to the many side

9.169.16

Page 17: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations (continued)2. Represent Relationships (continued)

Binary or Unary 1:1 Three possible options:

a. Add the primary key of A as a foreign key of B

b. Add the primary key of B as a foreign key of A

c. Both Binary and higher M:N relationships

Create another relation and include primary keys of all relations as primary key of new relation

9.179.17

Page 18: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

9.189.18

Page 19: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

Transforming E-R Diagrams into Relations (continued)

Unary 1:N Relationships Relationship between instances of a single entity type Utilize a recursive foreign key

A foreign key in a relation that references the primary key values of that same relation

Unary M:N Relationships Create a separate relation Primary key of new relation is a composite of two

attributes that both take their values from the same primary key

9.199.19

Page 20: Functional Dependence An attribute A is functionally dependent on attribute(s) B if: given a value b for B there is one and only one corresponding value.

Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall

9.209.20


Recommended