Unit 2 Database Design - 1
Unit 2 Database Design - 1
Design
Database Design
• Functional Dependencies
• Inference Rules
• Functional Dependency Closure
• Minimal Cover
• Decomposition Properties
• Need of Normalization
• Normal Forms: 1NF, 2NF, 3NF and BCNF, Multi-valued Dependency,
4NF
Functional Dependencies
• Functional Dependency (FD) is a constraint that determines the relation of one
attribute to another attribute in a Database Management System (DBMS).
• The attributes of a table is said to be dependent on each other when an attribute of a
table uniquely identifies another attribute of the same table.
• For example: Suppose we have a student table with attributes: Stu_Id, Stu_Name,
Stu_Age. Here Stu_Id attribute uniquely identifies the Stu_Name attribute of student
table because if we know the student id we can tell the student name associated with
it. This is known as functional dependency and can be written as Stu_Id->Stu_Name
or in words we can say Stu_Name is functionally dependent on Stu_Id.
• Formally:
If column A of a table uniquely identifies the column B of same table then it can
represented as A->B (Attribute B is functionally dependent on attribute A)
• A->B The left side of FD is known as a determinant, the right side of the production is
known as a dependent.
Functional Dependencies
• Types of Functional Dependencies in DBMS
• There are mainly four types of Functional Dependency in DBMS. Following
are the types of Functional Dependencies in DBMS:
• Multivalued Dependency
• Trivial Functional Dependency
• Non-Trivial Functional Dependency
• Transitive Dependency
Functional Dependencies
• Multivalued Dependency:
• Multivalued dependency occurs in the situation where there are multiple
independent multivalued attributes in a single table.
• A multivalued dependency is a complete constraint between two sets of
attributes in a relation. It requires that certain tuples be present in a
relation. Car_model Maf_year Color
• In this example, maf_year and color are independent H001 2017 Metallic
of each other but dependent on car_model. H001 2017 Green
H005 2018 Metallic
• In this example, these two columns are said to be
H005 2018 Blue
multivalue dependent on car_model. H010 2015 Metallic
• This dependence can be represented like this: H033 2012 Gray
• car_model -> maf_year
• car_model-> colour
Emp_id Emp_name
Functional Dependencies AS555
AS811
Harry
George
• Trivial Functional Dependency in DBMS
• The Trivial dependency is a set of attributes which are called a trivial if the set of attributes are
included in that attribute.
• So, X -> Y is a trivial functional dependency if Y is a subset of X.
• Consider this table of with two columns Emp_id and Emp_name.
• {Emp_id, Emp_name} -> Emp_id is a trivial functional dependency as Emp_id is a subset of
{Emp_id,Emp_name}.
• Non Trivial Functional Dependency in DBMS
• Functional dependency which also known as a nontrivial dependency
occurs when A->B holds true where B is not a subset of A. Company CEO Age
• In a relationship, if attribute B is not a subset of attribute A, then it is Microsoft Satya Nadella 51
considered as a non-trivial dependency. Google Sundar Pichai 46
• (Company} -> {CEO} (if we know the Company, we knows the CEO name) Apple Tim Cook 57
• But CEO is not a subset of Company, and hence it’s non-trivial functional
dependency.
Company CEO Age
• Augmentation rule: When a -> b holds, and c is attribute set, then ac -> bc
also holds. That is adding attributes which do not change the basic
dependencies.
• For example {STU_ID, NAME} →{ DEPT_BUILDING} is valid then {STU_ID,
NAME,DEPT_NAME} →{ DEPT_BUILDING,DEPT_NAME} is also valid.
Functional Dependencies
• Inference Rules of Functional Dependencies
• Below are the Three most important rules for Functional Dependency in
Database:
• Transitivity rule: This rule is very much similar to the transitive rule in
algebra if x -> y holds and y -> z holds, then x -> z also holds. X -> y is called
as functionally that determines y.
• For example, if STU_ID→CLASS, CLASS→LECTURE_HALL holds true then
according to the axiom of transitivity, STU_ID→LECTURE_HALL will also
hold true.
Functional Dependencies
• Inference Rules of Functional Dependencies
• Union Rule (IR4)
• This rule is also known as the additive rule. if X determines Y and X determines Z, then X
also determines both Y and Z.
• If X → Y and X → Z then X → YZ
• For example, STU_ID → STU_NAME, STU_ID→COURSE then STU_ID→ {STU_NAME,
COURSE} holds true.
• Proof:
• 1. X → Y (given)
• 2. X → Z (given)
• 3. X → XY (using IR2 on 1 by augmentation with X)
• 4. XY → YZ (using IR2 on 2 by augmentation with Y)
• 5. X → YZ (using IR3 on 3 and 4)
Functional Dependencies • Pseudo transitive Rule (IR6)
• Inference Rules of Functional • In the pseudo transitive rule, if X
Dependencies determines Y, and YZ determines W,
• Decomposition Rule (IR5) then XZ also determines W.
• This rule is the reverse of the Union rule • If X → Y and YZ → W then XZ → W
and is also known as the project rule. • Proof:
• if X determines Y and Z together, then X • 1. X → Y (given)
determines Y and Z separately
• For example STU_ID→ {STU_NAME, COURSE}
• 2. WY → Z (given)
then STU_ID → STU_NAME, STU_ID→COURSE • 3. WX → WY (using IR2 on 1 by augmenting
holds true. with W)
• If X → YZ then X → Y and X → Z • 4. WX → Z (using IR3 on 3 and 2)
• Proof:
• 1. X → YZ (given)
• 2. YZ → Y (using IR1 Rule)
• 3. X → Y (using IR3 on 1 and 2)
Functional Dependency Closure
• Finding Closure of an attribute set
• Attribute Closure of an attribute set
• You can follow the steps to find the Closure of an
is defined as a set of all attributes
attribute set:
that can be functionally
determined from it. 1. Determine A+, the Closure of A under functional
dependency set F.
• Closure of an attribute x is the set 2. A+: = will contain A itself; For example, if we need to
of all attributes that are functional find the closure of an attribute X, the closure will
dependencies on X with respect to incorporate the X itself and the other attributes that
F. It is denoted by X+ which means the X attribute can determine.
what X can determine. 3. Repeat the process as
• The closure of an attribute is 4. old A+: = A Closure;
represented as + 5. for each FB X → Y in the FD set, do
6. if X Closure is a subset of X, then A Closure:= A
Closure U Y;
7. Repeat until ( A+= old A+);
Functional Dependency Closure
• Step-1 : Add the attributes which are present on Left Hand Side in the original functional
dependency.
• Step-2 : Now, add the attributes present on the Right Hand Side of the functional
dependency.
• Step-3 : With the help of attributes present on Right Hand Side, check the other
attributes that can be derived from the other given functional dependencies. Repeat this
process until all the possible attributes which can be derived are added in the closure.
• Example-1 : Consider the table student_details having (Roll_No, Name,Marks, Location)
as the attributes and having two functional dependencies.
• FD1 : Roll_No -> Name, Marks
• FD2 : Name -> Marks, Location
• Now, We will calculate the closure of all the attributes present in the relation using the
three steps.
Functional Dependency Closure
• Example: Calculate closure of Roll_No
• Step-1 : Add attributes present on the LHS of the first functional dependency to the
closure.
• {Roll_no}+ = {Roll_No}
• Step-2 : Add attributes present on the RHS of the original functional dependency to the
closure.
• {Roll_no}+ = {Roll_No, Marks}
• Step-3 : Add the other possible attributes which can be derived using attributes present
on the RHS of the closure. So Roll_No attribute cannot functionally determine any
attribute but Name attribute can determine other attributes such as Marks and Location
using 2nd Functional Dependency(Name -> Marks, Location).
• Therefore, complete closure of Roll_No will be :
• {Roll_no}+ = {Roll_No, Marks, Name, Location}
Functional Dependency Closure
• Similarly, we can calculate closure for other attributes too i.e “Name”.
• Step-1 : Add attributes present on the LHS of the functional dependency
to the closure.
• {Name}+ = {Name}
• Step-2 : Add the attributes present on the RHS of the functional
dependency to the closure.
• {Name}+ = {Name, Marks, Location}
• Step-3 : Since, we don’t have any functional dependency where “Marks
or Location” attribute is functionally determining any other attribute ,
we cannot add more attributes to the closure. Hence complete closure
of Name would be :
• {Name}+ = {Name, Marks, Location}
Functional Dependency Closure
• Calculate Closure for Marks and Location attribute:
• We don’t have any Functional dependency where marks and
location can functionally determine any attribute. Hence, for those
attributes we can only add the attributes themselves in their
closures. Therefore,
• {Marks}+ = {Marks} and {Location}+ = { Location}
Functional Dependency Closure: Example
Examples
Functional Dependency Closure: Example
Examples:01
• Consider a relation R (A,B,C,D,E,F,G) With the
functional Dependencies
• A-BC
• BC-DE
• D-F
• CF-G
• A) CD-AC
• B) BD-CD
• C) BC-CD
• D) AC-BC
Decomposition Properties
• When a relation in the relational model is not appropriate normal form then
the decomposition of a relation is required.
• In a database, breaking down the table into multiple tables termed as
decomposition.
• If the relation has no proper decomposition, then it may lead to problems
like loss of information.
• Decomposition is used to eliminate some of the problems of bad design like
anomalies, inconsistencies, and redundancy.
• Types of Decomposition
EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME
Normalization
What is Normalization?
• Normalization is the process of organizing the data in the database.
• Normalization is used to minimize the redundancy from a relation or set of relations.
• It is also used to eliminate undesirable characteristics like Insertion, Update, and
Deletion Anomalies.
• Normalization divides the larger table into smaller and links them using
relationships.
• Most commonly used normal forms:
• First normal form(1NF)
• Second normal form(2NF)
• Third normal form(3NF)
• Boyce & Codd normal form (BCNF)
• Fourth Normal Form(4NF)
Normalization Form
Fourth Normal
Form(4NF)
Why do we need Normalization?
• The main reason for normalizing the relations is removing these anomalies. Failure
to eliminate anomalies leads to data redundancy and can cause data integrity and
other problems as the database grows.
• Update anomalies − When we try to update one data item having its copies scattered
over several places, a few instances get updated properly while a few others are left
with old values. Such instances leave the database in an inconsistent state.
• Deletion anomalies − We tried to delete a record, but parts of it was left undeleted
because of unawareness, the data is also saved somewhere else.
• Insert anomalies − We tried to insert data in a record that does not exist at all.
• Normalization is a method to remove all these anomalies and bring the database to
a consistent state.
• Normalization consists of a series of guidelines that helps to guide you in creating a
good database structure.
• Example: Relation EMPLOYEE is not in 1NF because
First normal form(1NF) of multi-valued attribute EMP_PHONE.
EMP_ID EMP_NAME EMP_PHONE EMP_STATE