Вы находитесь на странице: 1из 24

First Normal Form

Common to both PK and


Candidate Key Versions

2001 Irwin Levinstein

Definition
A relation is in 1NF if all attribute
values are atomic
Atomic: cannot be further broken
down
NO multivalued attributes
NO nested relations

2001 Irwin Levinstein

Cure for Non-1nf Relations


NESTING is eliminated by flattening:
ENAME(FNAME MI LNAME)
becomes FNAME MI LNAME
and ENAME is discarded.

2001 Irwin Levinstein

Cure for Nested Attributes


Nested
Attributes

MI
Fname
Lname

SSN

Name
EMPLOYEE

Name
disappears

2001 Irwin Levinstein

EMPLOYEE
SSN Fname MI Lname

Cure for Nested Attributes


Nested
Attributes

MI
Fname
Lname

SSN

Name
EMPLOYEE

Name
disappears

2001 Irwin Levinstein

EMPLOYEE
SSN Fname MI Lname

Cure for Non-1nf Relations


(cont.)
MULTIPLE VALUES eliminated in two
conceptual steps:
Replicate all info in other fields for each
value in multiple value field.
Use Projection Cure to reduce
redundancy

Projection Cure is basic tool of


normalization
2001 Irwin Levinstein

Replicate Information
R_1
DNAME | DNUM | MSSN | DLOCs
Rsch
5
333
Bell,Suga,Hous

R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous
2001 Irwin Levinstein

Replicate Information
R_1
DNAME | DNUM | MSSN | DLOCs
Rsch
5
333
Bell,Suga,Hous

R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous
2001 Irwin Levinstein

Use Projection Cure


R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous

R_4
R_3
DNAME | DNUM | MSSN
Rsch
5
333
2001 Irwin Levinstein

DNUM | DLOC
5
Bell
5
Suga
5
Hous

Use Projection Cure


R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous

dname,
dname,dnum,
dnum,mssn(R_2)
R_3
DNAME | DNUM | MSSN
Rsch
5
333
2001 Irwin Levinstein

R_4
DNUM | DLOC
5
Bell
5
Suga
5
Hous

Use Projection Cure


R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous

dname,
dname,dnum,
dnum,mssn(R_2)
R_3
DNAME | DNUM | MSSN
Rsch
5
333
2001 Irwin Levinstein

dnum,
dnum,dloc(R_2)
R_4
DNUM | DLOC
5
Bell
5
Suga
5
Hous

Use Projection Cure


R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous

dname,
dname,dnum,
dnum,mssn(R_2)

dnum,
dnum,dloc(R_2)

R_3
DNAME | DNUM | MSSN
Rsch
5
333
2001 Irwin Levinstein

Redundancy Reduced

R_4
DNUM | DLOC
5
Bell
5
Suga
5
Hous

Use Projection Cure


R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous

dname,
dname,dnum,
dnum,mssn(R_2)

dnum,
dnum,dloc(R_2)

R_3
DNAME | DNUM | MSSN
Rsch
5
333
2001 Irwin Levinstein

Redundancy Reduced

Foreign key

R_4
DNUM | DLOC
5
Bell
5
Suga
5
Hous

Re-create Original With Join


R_4
R_3
DNAME | DNUM | MSSN
Rsch
5
333

DNUM | DLOC
5
Bell
5
Suga
5
Hous

R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous
2001 Irwin Levinstein

Re-create Original With Join


R_4
R_3
DNAME | DNUM | MSSN
Rsch
5
333

DNUM | DLOC
5
Bell
5
Suga
5
Hous

R_3 (dnum),(dnum)R_4
R_2
DNAME | DNUM | MSSN | DLOC
Rsch
5
333
Bell
Rsch
5
333
Suga
Rsch
5
333
Hous
2001 Irwin Levinstein

Curing Dependency Problems


Conversion to 1nf involved no FDs
Normalization to 2nf, 3nf, bcnf
involves FDs
Based on an "offending FD: that does
not meet requirements
Projection Cure removes offending
FD from relation
2001 Irwin Levinstein

Example of Projection Cure


Suppose R = {A,B,C,D,E,F}
and offending FD is BC F.
Projecting the dependency creates two
new relations:
one based on the offending FD
fields BC and F, with key BC

one with all attributes except RHS of


offending dependency

fields ABCD and E


fields on LHS of dependency (BC) become FK.

2001 Irwin Levinstein

Example of Projection Cure


offending dependency: BC F
R_1
A

2001 Irwin Levinstein

R_3

R_2
A

Example of Projection Cure


offending dependency: BC F
R_1
A

B,C,F(R_1)
R_3

R_2
A

2001 Irwin Levinstein

Example of Projection Cure


offending dependency: BC F
R_1
A

2001 Irwin Levinstein

R_3

R_2
|

B,C,F(R_1)

A,B,C,D,E(R_1)
A

Example of Projection Cure


offending dependency: BC F
R_1
A

R_3

R_2
|

B,C,F(R_1)

A,B,C,D,E(R_1)
A

|
Key

2001 Irwin Levinstein

Example of Projection Cure


offending dependency: BC F
R_1
A

Foreign Key

2001 Irwin Levinstein

R_3

R_2
|

B,C,F(R_1)

A,B,C,D,E(R_1)
A

|
Key

Example of Projection Cure


offending dependency: BC F
F

Only the
RHS of
the
offending
FD is
projected
out

R_1
A

R_3

R_2
|

Foreign Key

2001 Irwin Levinstein

B,C,F(R_1)

A,B,C,D,E(R_1)
A

Key

To Come
When do dependencies offend?

2001 Irwin Levinstein

Вам также может понравиться