0% found this document useful (0 votes)
30 views

A Simplified COMPANY Relational Database Schema: Slide 10-1

The document discusses database normalization concepts including functional dependencies, normal forms, and anomalies that can occur when data is not properly normalized. It provides examples of first normal form, second normal form, third normal form, BCNF and describes the characteristics that define each normal form such as eliminating transitive dependencies and ensuring dependencies are on candidate keys. The goal of normalization is to avoid update anomalies by removing redundant data and dividing relations into smaller, more manageable pieces.

Uploaded by

Kiran Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

A Simplified COMPANY Relational Database Schema: Slide 10-1

The document discusses database normalization concepts including functional dependencies, normal forms, and anomalies that can occur when data is not properly normalized. It provides examples of first normal form, second normal form, third normal form, BCNF and describes the characteristics that define each normal form such as eliminating transitive dependencies and ensuring dependencies are on candidate keys. The goal of normalization is to avoid update anomalies by removing redundant data and dividing relations into smaller, more manageable pieces.

Uploaded by

Kiran Ramesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

A simplified COMPANY relational database

schema

Slide 10- 1
Figure 10.3 Two relation schemas suffering from
update anomalies

Slide 10- 2
May 2012 91.2814 3
• Information is stored redundantly
– Wastes storage
– Causes problems with update anomalies
• Insertion anomalies
• Deletion anomalies
• Modification anomalies

May 2012 91.2814 4


Normalization of Relations
• Normalization:
– The process of decomposing unsatisfactory "bad"
relations by breaking up their attributes into
smaller relations

• Normal form:
– Condition using keys and FDs of a relation to
certify whether a relation schema is in a particular
normal form
Slide 10- 5
Normalization

Normalization is a process that “improves” a database


design by generating relations that are of higher normal
forms.

The objective of normalization:


“to create relations where every dependency is on the key,
the whole key, and nothing but the key”.

91.2914 6
Normalization
There is a sequence to normal forms:
1NF is considered the weakest,
2NF is stronger than 1NF,
3NF is stronger than 2NF, and

Also,
any relation in 3NF is in 2NF; and
any relation in 2NF is in 1NF.

91.2914 7
Normalization

1NF a relation in BCNF, is also


in 3NF
2NF a relation in 3NF is also in
2NF
3NF
a relation in 2NF is also in
1NF
BCNF

91.2914 8
Functional Dependencies (2)
• X -> Y holds if whenever two tuples have the same value for X,
they must have the same value for Y

– For any two tuples t1 and t2 in any relation instance r(R): If


t1[X]=t2[X], then t1[Y]=t2[Y]

Slide 10- 9
Examples of FD constraints (1)
• Social security number determines employee
name
– SSN -> ENAME
• Project number determines project name and
location
– PNUMBER -> {PNAME, PLOCATION}
• Employee ssn and project number determines
the hours per week that the employee works on
the project
– {SSN, PNUMBER} -> HOURS
Slide 10- 10
Functional Dependencies

Example: Suppose we keep track of employee email


addresses, and we only track one email address for each
employee. Suppose each employee is identified by their
unique employee number. We say there is a functional
dependency of email address on employee number:

employee number  email address

91.2914 11
Functional Dependencies
EmpNum EmpEmail EmpFname EmpLname
123 [email protected] John Doe
456 [email protected] Peter Smith
555 [email protected] Alan Lee
633 [email protected] Peter Doe
787 [email protected] Alan Lee

If EmpNum is the PK then the FDs:


EmpNum  EmpEmail
EmpNum  EmpFname
EmpNum  EmpLname
must exist.

91.2914 12
Functional Dependencies
EmpNum  EmpEmail
EmpNum  EmpFname 3 different ways
EmpNum  EmpLname you might see FDs
depicted
EmpEmail
EmpNum EmpFname
EmpLname

EmpNum EmpEmail EmpFname EmpLname

91.2914 13
2.2 Inference Rules for FDs (1)

• Given a set of FDs F, we can infer additional FDs that


hold whenever the FDs in F hold
 Armstrong's inference rules:
IR1. (Reflexive) If Y subset-of X, then X -> Y
IR2. (Augmentation) If X -> Y, then XZ -> YZ
(Notation: XZ stands for X U Z)
IR3. (Transitive) If X -> Y and Y -> Z, then X -> Z

•  IR1, IR2, IR3 form a sound and complete set of


inference rules

Chapter 10-14
Inference Rules for FDs (2)

Some additional inference rules that are useful:


(Decomposition) If X -> YZ, then X -> Y and X -> Z
(Union) If X -> Y and X -> Z, then X -> YZ
(Psuedotransitivity) If X -> Y and WY -> Z, then WX -> Z

•  The last three inference rules, as well as any other


inference rules, can be deduced from IR1, IR2, and
IR3 (completeness property)

Chapter 10-15
Chapter 10-16
May 2012 91.2814 17
May 2012 91.2814 18
May 2012 91.2814 19
3.2 First Normal Form
• Disallows
– composite attributes
– multivalued attributes
– nested relations; attributes whose values for an
individual tuple are non-atomic

• Considered to be part of the definition of


relation

Slide 10- 20
Figure 10.8 Normalization into 1NF

Dname Dnumber Dmgr_ssn


Dnumber Dlocation

Slide 10- 21
Figure 10.9 Normalization nested relations into
1NF

Slide 10- 22
3.3 Second Normal Form (1)
• Uses the concepts of FDs, primary key
• Definitions
– Prime attribute: An attribute that is member of the primary key
K
– Full functional dependency: a FD Y -> Z where removal of any
attribute from Y means the FD does not hold any more
• Examples:
– {SSN, PNUMBER} -> HOURS is a full FD since neither SSN ->
HOURS nor PNUMBER -> HOURS hold
– {SSN, PNUMBER} -> ENAME is not a full FD (it is called a partial
dependency ) since SSN -> ENAME also holds

Slide 10- 23
Second Normal Form (2)
• A relation schema R is in second normal form
(2NF) if every non-prime attribute A in R is
fully functionally dependent on the primary
key

• R can be decomposed into 2NF relations via


the process of 2NF normalization

Slide 10- 24
Figure 10.10 Normalizing into 2NF and 3NF

Slide 10- 25
Normalization into 2NF and 3NF

Slide 10- 26
3.4 Third Normal Form (1)
• Definition:
– Transitive functional dependency: a FD X -> Z that
can be derived from two FDs X -> Y and Y -> Z
• Examples:
– SSN -> DMGRSSN is a transitive FD
• Since SSN -> DNUMBER and DNUMBER -> DMGRSSN hold
– SSN -> ENAME is non-transitive
• Since there is no set of attributes X where SSN -> X and X
-> ENAME

Slide 10- 27
Third Normal Form (2)
• A relation schema R is in third normal form (3NF) if it is in
2NF and no non-prime attribute A in R is transitively
dependent on the primary key
• R can be decomposed into 3NF relations via the process of
3NF normalization
• NOTE:
– In X -> Y and Y -> Z, with X as the primary key, we consider this a
problem only if Y is not a candidate key.
– When Y is a candidate key, there is no problem with the
transitive dependency .
– E.g., Consider EMP (SSN, Emp#, Salary ).
• Here, SSN -> Emp# -> Salary and Emp# is a candidate key.

Slide 10- 28
General Normal Form Definitions (2)

Definition:
• Superkey of relation schema R - a set of attributes S
of R that contains a key of R

Chapter 10-29
5 BCNF (Boyce-Codd Normal Form)

• A relation schema R is in Boyce-Codd Normal Form


(BCNF) if whenever an FD X -> A holds in R, then X is
a superkey of R

Chapter 10-30
Figure 10.12 Boyce-Codd normal form

Note: The above figure is now called Figure 10.12 in Edition 4


Chapter 10-31
Fully Functional Dependency
FD1: InvNum,LineNum Qty, InvDate

If a non-key attribute depends on Prime key attribute


then it is called as fully functional dependency.

InvNum LineNum Qty InvDate

May 2012 91.2814 32


Transitive dependency
Transitive dependency

Consider attributes A, B, and C, and where


A  B and B  C.
Functional dependencies are transitive, which
means that we also have the functional dependency
AC
We say that C is transitively dependent on A
through B.

91.2914 33
Transitive dependency
EmpNum  DeptNum

EmpNum EmpEmail DeptNum DeptNname

DeptNum  DeptName

EmpNum EmpEmail DeptNum DeptNname

DeptName is transitively dependent on EmpNum via DeptNum


EmpNum  DeptName

91.2914 34
Partial dependency
A partial dependency exists when an attribute B is
functionally dependent on an attribute A, and A is a
component of a multipart candidate key.
FD2: InvNum InvDate

InvNum LineNum Qty InvDate

Candidate keys: {InvNum, LineNum} InvDate is


partially dependent on {InvNum, LineNum} as
InvNum is a determinant of InvDate and InvNum is
part of a candidate key
91.2914 35
First Normal Form
First Normal Form
We say a relation is in 1NF if all values stored in the
relation are single-valued and atomic.

1NF places restrictions on the structure of relations.


Values must be simple.

91.2914 36
First Normal Form
The following in not in 1NF

EmpNum EmpPhone EmpDegrees


123 233-9876
333 233-1231 BA, BSc, PhD
679 233-1231 BSc, MSc

EmpDegrees is a multi-valued field:


employee 679 has two degrees: BSc and MSc
employee 333 has three degrees: BA, BSc, PhD

91.2914 37
First Normal Form
EmpNum EmpPhone EmpDegrees
123 233-9876
333 233-1231 BA, BSc, PhD
679 233-1231 BSc, MSc

To obtain 1NF relations we must, without loss of


information, replace the above with two relations -
see next slide

91.2914 38
First Normal Form
EmployeeDegree
Employee
EmpNum EmpDegree
EmpNum EmpPhone
333 BA
123 233-9876
333 BSc
333 233-1231
333 PhD
679 233-1231
679 BSc
679 MSc

An outer join between Employee and EmployeeDegree will


produce the information we saw before

91.2914 39
Second Normal Form
Second Normal Form
A relation is in 2NF if it is in 1NF, and every non-key
attribute is fully dependent on each candidate key. (That is, we
don’t have any partial functional dependency.)

• 2NF (and 3NF) both involve the concepts of key and


non-key attributes.
• A key attribute is any attribute that is part of a key;
any attribute that is not a key attribute, is a non-key attribute.
• Relations that are not in BCNF have data redundancies
• A relation in 2NF will not have any partial dependencies

91.2914 40
Second Normal Form
Consider this InvLine table (in 1NF):
InvNum LineNum ProdNum Qty InvDate
InvNum, LineNum ProdNum, Qty
There are two
candidate keys.
Qty is the only non-
key attribute, and it is
InvNum InvDate
dependent on InvNum

InvLine is not 2NF since there is a partial


dependency of InvDate on InvNum InvLine is
only in 1NF

91.2914 41
Second Normal Form
InvLine
InvNum LineNum ProdNum Qty InvDate
The above relation has redundancies: the invoice date is
repeated on each invoice line.
We can improve the database by decomposing the relation
into two relations:
InvNum LineNum ProdNum Qty

InvNum InvDate

Question: What is the highest normal form for these


relations? 2NF? 3NF? BCNF?
91.2914 42
Is the following relation in 2NF?

inv_no line_no prod_no prod_desc qty

91.2914 43
2NF, but not in 3NF, nor in BCNF:

EmployeeDept
ename ssn bdate address dnumber dname

since dnumber is not a candidate key and we have:

dnumber  dname.

91.2914 44
Third Normal Form
Third Normal Form
• A relation is in 3NF if the relation is in 1NF and all
determinants of non-key attributes are candidate keys
That is, for any functional dependency: X  Y, where Y is
a non-key attribute (or a set of non-key attributes), X is a
candidate key.
• This definition of 3NF differs from BCNF only in the
specification of non-key attributes - 3NF is weaker than
BCNF. (BCNF requires all determinants to be candidate
keys.)
• A relation in 3NF will not have any transitive dependencies
of non-key attribute on a candidate key through another
non-key attribute.
91.2914 45
5. Multivalued Dependencies and
Fourth Normal Form (1)
Definition:
• A multivalued dependency (MVD) X —>> Y specified on relation schema
R, where X and Y are both subsets of R, specifies the following constraint
on any relation state r of R: If two tuples t1 and t2 exist in r such that t1[X]
= t2[X], then two tuples t3 and t4 should also exist in r with the following
properties, where we use Z to denote (R 2 (X υ Y)):
– t3[X] = t4[X] = t1[X] = t2[X].
– t3[Y] = t1[Y] and t4[Y] = t2[Y].
– t3[Z] = t2[Z] and t4[Z] = t1[Z].
• An MVD X —>> Y in R is called a trivial MVD if (a) Y is a subset of X, or (b)
X υ Y = R.

Slide 14-56
Multivalued Dependencies and
Fourth Normal Form (3)
Definition:
• A relation schema R is in 4NF with respect to a set of
dependencies F (that includes functional dependencies and
multivalued dependencies) if, for every nontrivial
multivalued dependency X —>> Y in F+, X is a superkey for R.
– Note: F+ is the (complete) set of all dependencies (functional
or multivalued) that will hold in every relation state r of R that
satisfies F. It is also called the closure of F.

Slide 14-57
Figure 14.15 Fourth and fifth
normal forms.

Figure 14.15
Fourth and fifth normal forms. (a) The EMP relation with two MVDs: Ename –>> Pname and Ename –>> Dname. (b) Decomposing the
EMP relation into two 4NF relations EMP_PROJECTS and EMP_DEPENDENTS. (c) The relation SUPPLY with no MVDs is in 4NF but not in
5NF if it has the JD(R1, R2, R3). (d) Decomposing the relation SUPPLY into the 5NF relations R1, R2, R3.

Slide 14- 48
6. Join Dependencies and Fifth
Normal Form (1)
Definition:
• A join dependency (JD), denoted by JD(R1, R2, ..., Rn), specified
on relation schema R, specifies a constraint on the states r of
R.
– The constraint states that every legal state r of R should have a
non-additive join decomposition into R1, R2, ..., Rn; that is, for
every such r we have
– * (R1(r), R2(r), ..., Rn(r)) = r
Note: an MVD is a special case of a JD where n = 2.
• A join dependency JD(R1, R2, ..., Rn), specified on relation
schema R, is a trivial JD if one of the relation schemas Ri in
JD(R1, R2, ..., Rn) is equal to R.
Slide 14- 49
Join Dependencies and Fifth Normal
Form (2)
Definition:
• A relation schema R is in fifth normal form (5NF)
(or Project-Join Normal Form (PJNF)) with
respect to a set F of functional, multivalued, and
join dependencies if,
– for every nontrivial join dependency JD(R1, R2, ..., Rn) in
F+ (that is, implied by F),
• every Ri is a superkey of R.
• Discovering join dependencies in practical databases with
hundreds of relations is next to impossible. Therefore, 5NF is
rarely used in practice.
Slide 14- 50

You might also like