RDBMS UNIT3 FDs NORMALIZATION
RDBMS UNIT3 FDs NORMALIZATION
UNIT – 3
Database Design
https://www.youtube.com/watch?v=fiPXoICNAoQ
https://www.youtube.com/watch?v=NFk9sDJk50U
https://www.youtube.com/watch?v=gInecSg-36Y
Functional Dependency
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:
Account Relation:
ano balance bname
A02 25000 B
A03 33000 A
2
Explain different types of FD with the help of example.
https://youtu.be/EomeOKmc2mA
1. Full Dependency
2. Partial Dependency
3. Transitive Dependency
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
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.
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
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:
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.
6
What can be the Primary key in this table?
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…
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
1. It should be in 1NF.
2. It should not have any partial Dependencies.
A B
PRIME NON-PRIME
ATTRIBUTEs ATTRIBUTE
EXAMPLE:
Relation: Customer
8
Candidate Key (Composite key): {CUSTID, STOREID}
Primary key attributes: CUSTID and STOREID
Non- Prime attributes: Location
Problem:
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
1. It should be in a 2NF.
2. It should not have Transitive Dependency.
A B
Non-PRIME Non-PRIME
ATTRIBUTE ATTRIBUTE
10
FOR EXAMPLE:
11
Solution:
12
BCNF(BOYCE CODD NORMAL FORM) or 3.5NF
https://www.youtube.com/watch?v=NNjUhvvwOrk&t=0s
1. It should be in a 3NF.
2. For any dependency A B, A should be a Super Key.
EXAMPLE:
Relation/Table: College_Enrollment
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
Professor Subject
Candidate key
14
4th Normal Form (NF)
1. It should be in BCNF.
2. It should not have Multi-Valued Dependency.
B1
A1
B2
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
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.
17