Sei sulla pagina 1di 28

Database Management System

(CSE249)
UNITS
UNIT 1 INTRODUCTION TO DATABASES

UNIT 2 RELATIONAL DATABASE LANGUAGE & INTEFACES

UNIT 3 NORMALIZATION IN DESIGN OF DATABASES

UNIT 4 TRANSACTION MANAGEMENT


UNIT 5 CONCURRENCY CONTROL
Contents – UNIT 3
Normalization in Design of Databases
Unit 3 Topic 1 Functional Dependency, Different anomalies in
designing a Database, Normalization first

Unit 3 Topic 2 Second and third normal forms, BoyceCodd normal


form, multi-valued dependencies

Unit 3 Topic 3 Fourth normal forms, Inclusion dependencies, loss


less join decompositions
Contents
• Types of NF
• First Normal Form (1NF)
• Second Normal Form (2NF)
• Third Normal Form (3NF)
• Boyce-Codd Normal Form (BCNF)
• Fourth Normal Form (4NF)
• Fifth Normal Form (5NF) etc...
Recap

2NF: No Partial Dependency

3NF: No Transitive Dependency


Find the given table is in which NF?
• Let us assume a table User_Personal as given below;
• Is this table in First Normal Form?
– Yes. All the attributes contain only atomic values.
• Is this table in Second Normal Form?
– To verify this property, we need to find all the functional
dependencies which are holding in User_Personal table, and
have to identify a Primary key.
Find the given table is in which NF?
• This leads to the following set of FDs;
• F = { UserID → U_email Fname Lname City State, Zip; Zip → City State; City → Zip State }
• As UserID attribute can uniquely determine all the other attributes, we can have UserID
as the Primary key for User_Personal table.
• The next step is to check for the 2NF properties;
• Property 1 – The table should be in 1NF.
• Property 2 – There should not be any partial key dependencies.
• Primary key of our table is UserID and UserID is single simple attribute. As the key is not
composite, there is no chance for partial key dependency to hold. Hence property 2 is
also holding.
• User_Personal table is in 2NF.
Find the given table is in which NF?
• Is User_Personal in 3NF?
• To verify this we need to check the 3NF properties;
• Property 1 – Table should be in 2NF.
• Property 2 – There should not be any Transitive Dependencies in the
table.
• Table User_Personal is in 2NF, hence property 1 is satisfied.
• User_Personal table holds the following Transitive dependency;
• UserID → Zip, Zip → City State
• Hence, property 2 is not satisfied and the table is not in 3NF.
Find the given table is in which NF?
• Solution:
• Decompose User_Personal. For this, we can use the functional
dependencies Zip → City
• State and UserID → U_email Fname Lname City State Zip.
• As a result, we can have the following tables (primary keys are underlined);
• User_Personal (UserID, U_email, Fname, Lname, Zip)
• City (Zip, City, State)
• Both tables are in 3NF.
• Hence, tables are normalized to Third Normal Form.

Table - User_Personal Table – City


Boyce-Codd NF or 3.5 NF

• It is an advance version of 3NF that’s why it is also


referred as 3.5NF. BCNF is stricter than 3NF.
Boyce-Codd NF or 3.5 NF
• A table is in Boyce-Codd Normal form if
– It should be in the 3NF: For any dependency A-> B, Either A should be
Super Key or B should be a prime attribute. (i.e. to satisfy 3rd normal
for, either LHS of an FD should be super key or RHS should be prime
attribute OR non-prime attribute determines non-prime attribute)
– And if and only if at least one of the following conditions are met for
each functional dependency A → B:
• A is a superkey
• It is a trivial functional dependency
• The dependency of an attributes is known as trivial functional dependency
if the set of attributes includes that attribute.
• Symbolically: A -> B is trivial functional dependency if B is a subset of A.
• For example: {Employee_ID, Employee_Name} –> Employee_ID is also a
trivial functional dependency since Employee_ID is a subset
of {Employee_ID, Employee_Name}.
Boyce-Codd NF or 3.5 NF
• A table is in Boyce-Codd Normal form if
– It should be in the 3NF: For any dependency A-> B, Either A
should be Super Key or B should be a prime attribute. (i.e. to
satisfy 3rd normal for, either LHS of an FD should be super key
or RHS should be prime attribute)
– And if and only if at least one of the following conditions are
met for each functional dependency A → B:
• A is a superkey
• It is a trivial functional dependency
• OR if a nonprime attribute that determines a prime attribute, the BCNF
requirements are not met.
Boyce-Codd NF or 3.5 NF: Example
Boyce-Codd NF or 3.5 NF: Example
• Example: Suppose there is a company wherein employees work in more
than one department.
The table is not in BCNF
• Functional dependencies in the table above: as neither emp_id nor
emp_id -> emp_nationality emp_dept alone are
keys.
emp_dept -> {dept_type, dept_no_of_emp} To be in 3.5NF, either
• Candidate key (Only one): {emp_id, emp_dept} LHD should be Super
Key or there must be
trivial dependency.

emp_id emp_nationality emp_dept dept_type dept_no_of_emp

Production
1001 Austrian D001 200
and planning
1001 Austrian stores D001 250
design and
1002 American technical D134 100
support
Purchasing
1002 American D134 600
department
Boyce-Codd NF or 3.5 NF: Example
• To make the table comply with BCNF we can break the table in three
tables like this:
• 1. emp_nationality table: C.key: emp_id 2. emp_dept table: C.key: emp_dept
emp_id emp_nationality emp_dept dept_type dept_no_of_emp
1001 Austrian Production
1002 American and planning D001 200

stores D001 250


3. emp_dept_mapping table: design and
C.key: {emp_id, emp_dept} technical D134 100
support
emp_id emp_dept
Purchasing D134 600
Production and department
1001 planning
1001 stores Functional dependencies:
emp_id -> emp_nationality
design and technical
1002 emp_dept -> {dept_type, dept_no_of_emp}
support
1002 Purchasing department This is now in BCNF as in both the functional
dependencies left side part is a key.
Boyce-Codd NF or 3.5 NF
Boyce-Codd NF or 3.5 NF

• saax
Boyce-Codd NF or 3.5 NF
4 Normal Form
th

• It should be in the Boyce-Codd Normal Form.


• And it should not have Multi-Valued
Dependency (MVD)
Multi-valued Dependency
• A table is said to have multi-valued dependency, if the
following conditions are true,
– For a dependency A → B, if for a single value of A,
multiple value of B exists, then the table may have multi-
valued dependency.
– Also, a table should have at-least 3 columns for it to have
a multi-valued dependency.
– And, for a relation R(A,B,C), if there is a multi-valued
dependency between, A and B, then B and C should be
independent of each other.
• If all these conditions are true for any relation(table), it is said
to have multi-valued dependency.
4th Normal Form
4th Normal Form
4th Normal Form
4th Normal Form
• Lets add one more field ‘address’ to Enrolment Table
4th Normal Form
Que1. Find the highest normal form of a relation R(A, B, C, D, E) with
FD set as: { BC->D, AC->BE, B->E }
• Explanation:
• Step-1: As we can see, (AC)+ ={A, C, B, E, D} but none of its subset can
determine all attribute of relation, So AC will be candidate key. A or C can’t
be derived from any other attribute of the relation, so there will be only 1
candidate key {AC}.
• Step-2: Prime attributes are those attribute which are part of candidate key
{A, C} in this example and others will be non-prime {B, D, E} in this example.
• Step-3: Find in which NF a relation is.
• The relation R is in 1st normal form as a relational DBMS does not allow
multi-valued or composite attribute.
• The relation is in 2nd normal form because BC->D is in 2nd normal form (BC
is not a proper subset of candidate key AC) and AC->BE is in 2nd normal form
(AC is candidate key) and B->E is in 2nd normal form (B is not a proper subset
of candidate key AC). [There is no Partial Dependency]
• The relation is not in 3rd normal form because in BC->D (neither BC is a
super key nor D is a prime attribute) and in B->E (neither B is a super key nor
E is a prime attribute) but to satisfy 3rd normal for, either LHS of an FD
should be super key or RHS should be prime attribute. So the highest normal
form of relation will be 2nd Normal form.
Que2. Consider these functional dependencies of some relation
R, (A, B, C) with FD = { AB ->C, C ->B, AB ->B}. Find whether the
relation is in 3NF. Given the relation is in 2NF and only candidate
key of R is AB.
• To satisfy 3rd normal for, either LHS of an FD should be super key
or RHS should be prime attribute. Here in C-> B, B is the prime
attribute.
• Also, the first and the third FD are in BCNF as they both contain
the candidate key (or simply KEY) on their left sides.
• The second dependency, however, is not in BCNF but is definitely
in 3NF due to the presence of the prime attribute on the right
side.
• So, the highest normal form of R is 3NF as all three FD’s satisfy
the necessary conditions to be in 3NF.

Potrebbero piacerti anche