0% found this document useful (0 votes)
29 views17 pages

RDBMS UNIT3 FDs NORMALIZATION

Normalization

Uploaded by

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

RDBMS UNIT3 FDs NORMALIZATION

Normalization

Uploaded by

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

RDBMS

UNIT – 3
Database Design

 Informal Design Guidelines for Relational Schema

https://www.youtube.com/watch?v=fiPXoICNAoQ

https://www.youtube.com/watch?v=NFk9sDJk50U

https://www.youtube.com/watch?v=gInecSg-36Y

 Define functional dependency.


https://www.youtube.com/watch?v=0kPPQxbNXIQ&t=0s

 Functional Dependency

 Let R be a relation schema.


 Let attributes X and Y are two subsets of relation R.
 If the values of the X component of a tuple uniquely (or
functionally) determine values of the Y component, then there is a
functional dependency from X to Y.
 This is denoted by X → Y.
 It is referred as: Y is functionally dependent on the X
OR
X functionally determines Y.
Where, X is a determinant and Y is a Dependent.
 The abbreviation for functional dependency is FD or fd.
 The set of attributes X is called the left hand side of the FD, and Y is
called the right hand side.

1
 The left hand side of the FD is also referred as determinant whereas
the right hand side of the FD is referred as dependent.

 Diagrammatic representation of FD
R:

X Y

FOR EXAMPLE:

 Consider the relation Account(ano, balance, aname).


 In this relation ano can determines balance and aname. So, there is a
functional dependency from ano to balance and aname.
 This can be denoted by ano → {balance, aname}.
 So can say, ano → {balance} and ano → {aname} means balace is
functionally dependent on ano and aname is funactionally dependent on
ano.

Account Relation:
ano balance bname

ano balance aname


A01 18000 A

A02 25000 B

A03 33000 A

2
 Explain different types of FD with the help of example.
https://youtu.be/EomeOKmc2mA

1. Full Dependency

 In a relation, the attribute B is fully functional dependent on A


if B is functionally dependent on A, but not on any proper
subset of A.
 Eg. {Roll_No, Department_Name, Semester} →SPI

2. Partial Dependency

 In a relation, the attribute B is partial functional dependent on A


if B is functionally dependent on A as well as on any proper
subset of A.
 If there is some attribute that can be removed from A and the still
dependency holds.
 Eg. {Enrollment_No, Student_Name} → SPI
 Here, Subset of determinant A say Enrollment_No alone can determine
SPI even if we removed Student_Name from A. So there is a Partial
Dependency

3. Transitive Dependency

 In a relation, if attribute(s) A→B and B→C, then C is transitively


depends on A via B (provided that A is not functionally dependent
on B or C).
 Eg. Emp_No → Branch_No and Branch_No → Branch_Name

4. Trivial FD
 X→Y is trivial FD if Y is a subset of X
 Eg.{Roll_No, Department_Name} → Roll_No
OR

3
{Roll_No, Department_Name} → Department_Name

5. Nontrivial FD
 X→Y is nontrivial FD if Y is not a subset of X
 Eg.. {Roll_No, Department_Name} → Student_Name

 What is normalization? What is the need of it?


https://www.youtube.com/watch?v=xoTyrdT9SZI&t=0s

 Normalization
 Database normalization is the process of removing or
reducing redundant data from your tables to improve
storage efficiency, data integrity, and scalability.
 Normalization generally involves splitting existing tables into
multiple ones, which must be re-joined or linked each time a
query is issued.
 Normalization is the process of organizing data in a database.
This includes creating tables and establishing relationships
between those tables according to rules designed both to protect
the data and to make the database more flexible by eliminating
redundancy and inconsistent dependency. Normal forms are
used to eliminate or reduce redundancy in database tables.

 Need of Normalization
 Eliminates redundant data
 Reduces chances of data errors
 Reduces disk space
 Improve data integrity, scalability and data consistency.

4
 Explain different types of normal forms with
example.

1st Normal Form (1NF)


https://www.youtube.com/watch?v=mUtAPbb1ECM&t=0s
Every table in your database should atleast follow the 1NF, always.
It is a 1st step of the Normalization Process to move on to 2 nd NF and 3rd NF.

 A table to be in 1NF should satisfy the following conditions:

1. Each column should contain atomic (Single) values (No Multi-


valued attribute is allowed). Entries like X,Y and Y,Z violets this
rule.

2. A column contains values that are of same type. Do not inter-mix


different types of value in a single column.

3. Each column should have unique name.

4. Order in which data entered and saved doesn’t matter. Using SQL
you can easily fetch data in any order from table.

Example: Table1

Rollno Name Course


1 Sita C/C++
2 Geeta JAVA
3 Rita C/DBMS

Problem:
The Above table (Relation) is not in a 1NF as it satisfies Rule 2, 3 and 4 but
violets Rule 1 i.e. It contains multi-valued attribute (course) which contains
more than one value for the same record.

5
 How to convert above Relation/ table in a 1NF?

Solution1:
We will break the multi-values into atomic value as shown below:
Above table1 will be represented like this and it is in 1NF:

Rollno Name Course


1 Sita C
1 Sita C++
2 Geeta JAVA
3 Rita C
3 Rita DBMS

What will be the primary key in above table?

We can clearly check that Rollno, Name and Course all the column contains
repetitive records so can’t specify a primary key but if we combine Rollno and
Course then definitely it will be a primary key (Rollno,Course) called
Composite Primary key / candidate key.

Solution2:
As shown in table1, Course is a multi-valued attribute which contains
maximum two values. Means one student is enrolled in maximum 2 courses.
So we will Divide Course Multi-valued attributes into two more columns say
Course1 and Course2 as shown below.

Rollno Name Course1 Course2


1 Sita C C++
2 Geeta JAVA NULL
3 Rita C DBMS

6
What can be the Primary key in this table?

Alone Rollno can be the primary key in this table.


Another Problem is that… it may be possible that one student is enrolled in N
no. of Courses OR A Student is enrolled only in a Single course so at that time
above table will be represented like:

Rollno Name Course1 Course2 Course3 Course4 … … CourseN


1 Sita C C++ DBMS PHP PYTHON
2 Geeta JAVA NULL NULL NULL NULL
3 Rita C DBMS NULL NULL NULL

The above table representation contains more no. of Nulls. So overall it is not
a good table representation. So you can represent in a third way:

Solution3:
In this we will divide the table1 into two different tables. So we will have…

Rollno Name Rollno Course


(P.K) (F.K.)
1 Sita 1 C
2 Geeta 1 C++
3 Rita 2 JAVA
3 C
3 DBMS

Primary key table will be known as Base Table. So if the student is enrolled
in N No. of course you just have to enter that in a base table once.

7
2nd Normal Form (2NF)

https://www.youtube.com/watch?v=R7UblSu4744&t=0s

 A table to be in 2NF should satisfy the following conditions:

1. It should be in 1NF.
2. It should not have any partial Dependencies.

Partial Key Means… Non-key attribute is partially dependent on the primary


key attribute.

Below figure shows Partial Dependency:

A B

PRIME NON-PRIME
ATTRIBUTEs ATTRIBUTE

Suppose, We have a Candidate Key: {PXY}

Partial Dependency PB (B is a No-Prime Attribute determined by a Prime


attribute P which is a Part of a candidate key).Means B does not depend on
PXY (Entire candidate key). This is called Partial Dependency.

EXAMPLE:
Relation: Customer

CUSTID STOREID LOCATION


1 1 DELHI
1 3 MUMBAI
2 1 DELHI
3 2 BANGLORE
4 3 MUMBAI

8
Candidate Key (Composite key): {CUSTID, STOREID}
Primary key attributes: CUSTID and STOREID
Non- Prime attributes: Location

Problem:

 As per the rule of 2NF, Non prime attribute LOCATION is fully


functionally dependent on candidate key i.e. {CUSTID, STOREID}
 As shown in above table there is a repetition in a STOREID attribute(X)
so will check for the repetition in LOCATION attribute(Y) And It is found
so we can say LOCATION is determined by STROEID only.
 In above table LOCATION is not fully dependent on primary key but
this attribute is partially dependent on primary key attribute
STOREID.
 As per the condition Partial Dependencies is not allowed in 2NF. So we
can say that above table is not in 2NF.

CUSTID STOREID LOCATION

 How to convert above table in a 2NF??

Solution:
 Decompose relation in such a way that resultant relation does not
have any partial FD (If any non prime attributes are determined by a
subset of a candidate key).
 For this purpose remove partial dependent attribute (LOCATION)
that violets 2NF from relation.
 Place them in separate new relation along with the prime attribute
on which they are fully dependent.
 The primary key of new relation will be the attribute on which it if
fully dependent i.e in our case STOREID.
 Keep other attribute same as in that table with same primary key.
 So above table can be decomposed as per following.

9
CUSTID STOREID STOREID LOCATION
1 1 1 DELHI
1 3
2 BANGLORE
2 1
3 2 3 MUMBAI
4 3

CUSTID STOREID STOREID LOCATION

3rd Normal Form (3NF)


https://www.youtube.com/watch?v=aAx_JoEDXQA&t=0s

A table to be in 3NF should satisfy the following conditions:

1. It should be in a 2NF.
2. It should not have Transitive Dependency.

Below figure shows Transitive Dependency:

A B

Non-PRIME Non-PRIME
ATTRIBUTE ATTRIBUTE

We can say that… An attribute C is transitively dependent on attribute A


(A C), if there exist an attribute B such that: A B and B  C.

10
FOR EXAMPLE:

 Here Column Exam_Name depends on the Primary key


(Student_id+Subject_id) both.
 For e.g. Mechanical student have workshop exam but IT student
wont. So Exam_name depends on Student_id.
 For CS students, we have practical exam of JAVA but for
Engineering MATHS or some students may not have. Means
Exam_name depends on Subject_id.
 So, here we can say that exam_name is depend on Student_id
and Subject_id both.
 There is a column total_marks, which doesn’t depend on
Student or subject but it depends on exam_name as there can be
different exam like theory/practical so the value of total_marks
changes based on Exam_name. Hence we can say total_marks is
depends on Exam_name.
 As shown in above table.. All columns are depends on
candidate key {student_id+Subject_id} except total_marks
which depends on a exam_name.
 But Exam_name is not a part of a Primary key. This is a
Transitive Dependency.

11
Solution:

 Decompose relation in such a way that resultant relation does not


have any non-prime attribute that are transitively dependent on
Primary key e.g Exam Table.
 For this purpose remove transitively dependent attribute
(total_marks) that violets 3NF from relation. Place them in separate
new relation (Exam table) along with the non-prime
attribute(exam_name) due to which transitive dependency
occurred. The primary key of new relation will be this non-prime
attribute (exam_name).
 Keep other attributes same as in that table with same primary key
(Score table).
 So above table can be decomposed as per following:

12
BCNF(BOYCE CODD NORMAL FORM) or 3.5NF
https://www.youtube.com/watch?v=NNjUhvvwOrk&t=0s

It is an upgraded version of 3NF.

A table to be in BCNF should satisfy the following conditions:

1. It should be in a 3NF.
2. For any dependency A B, A should be a Super Key.

In simple words we can say that A should not be a Non-prime attribute.


For a functional Dependency, if A B, A is a Non-Prime and B is a Prime
attribute then a table is not BCNF. BCNF does not allow this behavior .

EXAMPLE:
Relation/Table: College_Enrollment

Student_ID Subject Professor

101 JAVA P.JAVA


101 C++ P.CPP
102 JAVA P.JAVA2
103 C# P.CSHARP
104 JAVA P.JAVA

 As you can see in the above table, one student can enroll for multiple
subjects.
 Also note there can be multiple professors teaching one subject say for
JAVA
 Here {Student_ID + Subject} together forms a Primary key because
together this two can define other table columns.

 This table satisfies 1NF as all the tuple values are atomic.
 This table also satisfies 2NF, as there is No Partial Dependencies like

13
{Student_ID, Subject)  Professor

Professor Subject

 This table also satieties 3NF, as there is No Transitive Dependencies


like

{Student_ID, Subject)  Professor

Professor Subject

 This table doesn’t satisfy BCNF as….

Candidate key

{Student_ID, Subject)  Professor


Professor Subject

Non-Prime Attribute Prime Attribute


(NOT A SUPERKEY)

 How we can convert the table in BCNF?

Solution: We will break the table into two tables say:

Student Table Professor Table

Student_Id P_ID P_ID Professor Subject

14
4th Normal Form (NF)

 A table to be in 1NF should satisfy the following conditions:

1. It should be in BCNF.
2. It should not have Multi-Valued Dependency.

 What is Multi-Valued dependency is??

There are three conditions for a Multi-Valued Dependency:

1. A >B, for a single value of A, more than one value of B exist.

B1
A1
B2

2. A table should have at least 3 columns.

3. For this table with A,B, C columns, A> B have a multi-valued


dependency then B and C should be independent.

If all these are true for a table then we can say that the table may have
Multi-Value Dependency.

15
In a table a Multi-Valued dependency can exist between more columns also
look like A> B and A> C

Example:
Enrollment Table

S_id Course hobby


1 Science Cricket
1 Maths Hocky
2 C# Cricket
2 Php Hocky

 As you can see one student s_id=1 has enrolled for two
different courses say science and maths and has different
hobbies.
 There is a no relationship between course and hobby columns.
So it leads to a bad table design.
 Hence, the above table Enrollment will be decomposed into
two separate tables to solve the problem of Multi-Valued
dependency.

16
In some cases a table can have Functional Dependency and Multi-
Valued Dependency together.
FOR EXAMPLE:
Let’s add one more column to Enrollment table say Address.

So, the Original table will be decomposed into 3 separate tables


to satisfy 4NF as shown below:

17

You might also like