Skip to main content

Relational database design


Closure Of Functional Dependency Introduction


The Closure Of Functional Dependency means the complete set of all possible attributes that can be functionally derived from given functional dependency using the inference rules known as Armstrong’s Rules.
If “F” is a functional dependency then closure of functional dependency can be denoted using “{F}+”.

There are three steps to calculate closure of functional dependency. 

These are

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.


Closure Of Functional Dependency Examples


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 mentioned below.

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, Name,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 [icon name="long-arrow-right" class="" unprefixed_class=""] Marks, Location).

Therefore, complete closure of Roll_No will be 

{Roll_no}+ = {Roll_No, Marks, Name, Location}
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}
NOTE : 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}

Example-2 : Consider a relation R(A,B,C,D,E) having below mentioned functional dependencies.
FD1 : A->BC
FD2 : C->B
FD3 : D->E
FD4 : E ->D
Now, we need to calculate the closure of attributes of the relation R. The closures will be:
{A}+ = {A, B, C}
{B}+ = {B}
{C}+ = {B, C}
{D}+ = {D, E}
{E}+ = {E,D}


Calculating Candidate Key


“A Candidate Key of a relation is an attribute or set of attributes that can determine the whole relation or contains all the attributes in its closure."

Let’s try to understand how to calculate candidate keys.
Example-1 : Consider the relation R(A,B,C) with given functional dependencies :

FD1 : A->B
FD2 : B ->C

Now, calculating the closure of the attributes as :

{A}+ = {A, B, C}
{B}+ = {B, C}
{C}+ = {C}
Clearly, “A” is the candidate key as, its closure contains all the attributes present in the relation “R”. 

Example-2 : Consider another relation R(A, B, C, D, E) having the Functional dependencies 

FD1 : A  BC
FD2 : C  B
FD3 : D  E
FD4 : E  D

Now, calculating the closure of the attributes as :

{A}+ = {A, B, C}
{B}+ = {B}
{C}+ = {C, B}
{D}+ = {E, D}
{E}+ = {E, D}

In this case, a single attribute is unable to determine all the attribute on its own like in previous example. Here, we need to combine two or more attributes to determine the candidate keys.

{A, D}+ = {A, B, C, D, E}
{A, E}+ = {A, B, C, D, E}
Hence, "AD" and "AE" are the two possible keys of the given relation “R”. Any other combination other than these two would have acted as extraneous attributes.
NOTE : Any relation “R” can have either single or multiple candidate keys.

Example1:
Consider the following set F of functional dependencies

F= {
A ->BC
B ->C
A ->B
AB ->C
}

Steps to find canonical cover


There are two functional dependencies with the same set of attributes on the left:
A ->BC
A ->B
These two can be combined to get
A ->BC.
Now, the revised set F becomes:
F= {
A ->BC
B ->C
AB ->C
}

There is an extraneous attribute in AB ->C because even after removing AB ->C from the set F, we get the same closures. This is because B ->C is already a part of F.
Now, the revised set F becomes:
F= {
A ->BC
B ->C
}
C is an extraneous attribute in A ->BC, also A ->B is logically implied by A ->B and B  C (by transitivity).
F= {
A ->B
B ->C
}
After this step, F does not change anymore. So,
Hence the required canonical cover is,
Fc= {
A ->B
B ->C
}

Example 2

Consider another set F of functional dependencies:
F={
A ->BC
CD ->E
B ->D
E ->A
}
The left side of each functional dependency in F is unique.
None of the attributes in the left or right side of any functional dependency is extraneous (Checked by applying definition of extraneous attributes on every functional dependency).
Hence, the canonical cover  is equal to F.

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 the undesirable characteristics like Insertion, Update and Deletion Anomalies.

Normalization divides the larger table into the smaller table and links them using relationship.
The normal form is used to reduce redundancy from the database table.

Types of Normal Form


  • 1NF
  • 2NF
  • 3NF
  • BCNF

First Normal Form


A relation will be 1NF if it contains an atomic value.
It states that an attribute of a table cannot hold multiple values.

It must hold only single-valued attribute.
First normal form disallows the multi-valued attribute, composite attribute, and their combinations.

Example: Relation EMPLOYEE is not in 1NF because of multi-valued attribute EMP_PHONE.

Second Normal Form 2NF


In the 2NF, relational must be in 1NF.
In the second normal form, all non-prime attributes are fully functional dependent on the primary key

Example: Let's assume, a school can store the data of teachers and the subjects they teach. In a school, a teacher can teach more than one subject.


Consider Relation R(A,B,C,D) with functional dependancies
AB->D
B->C
From above relation & FD wecamn find out Candidate Key.

Candidate key for R(A,B,C,D) will be AB.
Because if if we will find (AB)+ then it will be Relation R.
So we can say AB is Candidate Kay.And also it will be the primary key.

Prime Attributes
and Non Prime Attributes


Here A & B are prime attributes because they are part of candidate key.
C & D are non prime attributes.
According to 2NF all non-prime attributes are fully functional dependent on the primary key,

In AB->D the non prime attribute D is fully functionally dependant on Primary key.
But In B->C the non prime attribute C is not fully functionally dependant on AB it is partially dependant on prime attribute.
Therefore relation is not in 2NF.
In 2NF Partial dependency is not allowed.


How to translate table in 2NF


Now lets decompose above relation R(A,B,C,D) .
In first table there will be always contain candidate Key and with those attributes which are entirely dependant on candidate key.

Therefore, R1(ABD) and R2(BC).
Now both tables can satisfy definition of 2NF.
Now in second table B is primary key.
So above relation is in 2NF.

R(ABCD)
AB->C
D->E 

So here Candidate Key will be ABD.
The C is non prime attribute which depends on proper subset of candidate key therefore here partial dependency is present.
So relation is not in 2NF.

Lets decompose relation.
R1(ABD)
R2(ABC)
R3(DE)

Third Normal Form


A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
If there is no transitive dependency for non-prime attributes, then the relation must be in third normal form.

A relation is in third normal form if it holds atleast one of the following conditions for every non-trivial function dependency X → Y.
X is a super key.
Y is a prime attribute, i.e., each element of Y is part of some candidate key.

The Relation R(A,B,C,D) is having following FD 
A->B
B->C

Check whether given relation is in 3NF or not.

Solution

Calculate Candidate key for given relation.
A will be Candidate key for given relation.
Lets Consider first F.D i.e. A->B
Here in this FD A is super key.
So Condition for 3NF is get satisfied. But in FD B->C B is not super key and C is non prime attribute it is not part of candidate key.
Therefore violating definition of 3NF.
Also in above relation transitive dependency is present.
So given relation is not in 3NF.
To convert the given relation in 3NF decompose the relation.
In first table there will be candidate key and its dependant attribute.
So R1(AB),Here A is key attribute.
In second table there will be B & C
S R2(BC),Here B is key attribute.
R1(AB)
R2(BC)
Now,above relation is in 3NF.

Boyce Codd Normal Form BCNF


BCNF is the advance version of 3NF. 
It is stricter than 3NF.
A table is in BCNF if every functional dependency X → Y, X is the super key of the table.
For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
Example: Let's assume there is a company where employees work in more than one department.

Super Key


Super key is set of attributes with the help of which you can uniquely identify a row or tuple in  a table or you can identify all the remaining attributes.

Candidate Key


Minimal super key is candidate key.
The super key is called candidate key if and only if its any proper subset should not be super key. 

Menu card just for you !

Select Your favourite topic to learn.

Comments

Trending⚡

Happy birthday Hardik Pandya | In C programming

  Happy birthday Hardik Pandya . Now you are  28 years old. Great achievement you have. Let's we want to talk more about Hardik pandya. He is great cricketer. Pandya is awesome. In this Blog Post we are going to wish pandya " Happy birthday using C program". Let's tune with us till end. Now we have to wish pandya, so we are going to use printf () function printing message to pandya as " Happy birthday Hardik pandya Now you are 28 years old". Hardik pandya was born on 11 October in 1993. Now we are going to declare a variable called as current_age = 2021 - 1993. It calculate current age Of Hardik pandya. See the "Happy birthday pandya" using c programming. If you liked this Blog Post then don't forget to share with your computer science learning friends. Once again " Happy birthday Hardik Pandya sir". Read also Happy Rakshabandhan wish using C program Friendship day 2021 greetings in C

Understanding link.click() in JavaScript

Hey! Today i am going to share with you how to use link.click() function in javascript As a JavaScript developer, you may come across the need to programmatically click a link on a web page. The link.click() method is a commonly used way to do this, and it is important to understand how it works and when to use it. What is link.click()? link.click() is a method that can be used to simulate a click on a link element in JavaScript. It is typically used when you want to trigger a link click event programmatically, rather than requiring the user to physically click the link. How to use link.click() Using link.click() is relatively straightforward. First, you need to select the link element you want to click using a DOM selector such as getElementById() or querySelector(). Then, you can call the click() method on the link element to simulate a click. Here is an example: // select the link element const myLink = document.getElementById('my-link'); // simulate a cl

Best course Recommendation of IT field in 2023

Recommend me best course 🎉50% Discount on registration today itself 🎉! Join Course Now In today's fast-paced digital age, staying updated with the latest technology trends is crucial for professionals looking to advance in their careers. With technology rapidly evolving, it is important to continuously upskill and gain new knowledge to stay relevant in the job market. In 2023, there are several courses in technology that are gaining popularity and are highly recommended for professionals seeking to enhance their skills in data science, analytics, and digital marketing. Data Science: Data science is an interdisciplinary field that combines statistical analysis, machine learning, and computer science to extract insights and knowledge from data. With the increasing amount of data available, data scientists are in high demand across various industries. The best courses in data science for 2023 are th

What is programming explained in simple words

Hi my dear friends today in this blog post we are going to know what programming is? In simple words I will explain to you programming. Nowadays we are watching real life use of programming. How computers learn to speak, talk and do the specified complex task for us. We are all keen to know what is exactly programming? Programming is the process of creating instructions that a computer can understand and execute. These instructions, also known as code, are written in a programming language that is specific to the task at hand. The history of programming can be traced back to the mid-20th century, with the development of the first electronic computers. The first programming languages were known as machine languages, which were specific to a particular type of computer. As computers became more sophisticated, high-level programming languages were developed, such as FORTRAN and COBOL, which were easier for humans to read and write. These languages allow programmers to write code t

Best Programming Languages to Learn in 2022-2023 | Programming Guide For Beginners

Hey everyone ! Today I am going to share with you which programming language you must learn and why you must learn in year 2022. There are so many programmers,coders, computer science students have a Question in their mind , Which programming language I should have to learn ? I am going to answer this very Important Question. Please tune with me till the end. This article will be very helpful for every computer science and coding enthusiast. Let's get started. The world of programming is dynamic. It means the need for language changes according to duration. Every year we see a new language. Everyone gives us feedback on which language we have to learn. But it's not about which language you must've learn , I would like to ask you whats your purpose is in learning a programming language. Why do you want to learn a programming language ? Well you have answers like I want to create softwares , Applications and websites, decentralised apps, cryptocurrency, blockchai

Friendship day 2021 | greetings

Celebrate this year international friendship day with computer programming languages. Send greetings to your friends by writing a block of code using C,C++, python etc. If you and your friends are interested in tech and computer science then it's one of the best way to wish your friends by sending a block of code through whatsapp message, status, instagram post, facebook post and story, instagram reels etc. Now we will discuss how you will write your code to wish your friend on friendship day 2021. Friendship day 2021 greetings using c program. Friendship day 2021 greetings using cplusplus program Friendship day 2021 greetings using python Program. At last we wish you a very happy friendship day to World citizens. Enjoy celebrate this friendship day online ,using digital greeting cards and art. Hope you like our Idea for greetings on this 2021 friendship day