0% found this document useful (0 votes)
4 views

Unit3[1]

Uploaded by

786luqmandanish
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)
4 views

Unit3[1]

Uploaded by

786luqmandanish
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/ 33

Unit-3

Functional Dependency
The functional dependency is a relationship that exists between two attributes. It
typically exists between the primary key and non-key attribute within a table.

1. X → Y
The left side of FD is known as a determinant, the right side of the production is
known as a dependent.

A functional dependency occurs when one attribute uniquely determines another


attribute within a relation. It is a constraint that describes how attributes in a table
relate to each other. If attribute A functionally determines attribute B we write
this as the A→B.
Functional dependencies are used to mathematically express relations among
database entities and are very important to understanding advanced concepts in
Relational Database Systems.

Example:
roll_no name dept_name dept_building

42 abc CO A4

43 pqr IT A3

44 xyz CO A4

45 xyz IT A3

46 mno EC B2

47 jkl ME B2

From the above table we can conclude some valid functional


dependencies:
• roll_no → { name, dept_name, dept_building },→ Here, roll_no can
determine values of fields name, dept_name and dept_building, hence
a valid Functional dependency
• roll_no → dept_name , Since, roll_no can determine whole set of
{name, dept_name, dept_building}, it can determine its subset
dept_name also.
• dept_name → dept_building , Dept_name can identify the
dept_building accurately, since departments with different dept_name
will also have a different dept_building
• More valid functional dependencies: roll_no → name, {roll_no, name}
⇢ {dept_name, dept_building}, etc.
Types of Functional Dependencies in DBMS
1. Trivial functional dependency
2. Non-Trivial functional dependency
3. Multivalued functional dependency
4. Transitive functional dependency
1. Trivial Functional Dependency
In Trivial Functional Dependency, a dependent is always a subset of the
determinant. i.e. If X → Y and Y is the subset of X, then it is called trivial
functional dependency
Example:
roll_no name age

42 abc 17

43 pqr 18

44 xyz 18

Here, {roll_no, name} → name is a trivial functional dependency, since


the dependent name is a subset of determinant set {roll_no,
name}. Similarly, roll_no → roll_no is also an example of trivial
functional dependency.
2. Non-trivial Functional Dependency
In Non-trivial functional dependency, the dependent is strictly not a
subset of the determinant. i.e. If X → Y and Y is not a subset of X, then it
is called Non-trivial functional dependency.
Example:
roll_no name age

42 abc 17

43 pqr 18

44 xyz 18

Here, roll_no → name is a non-trivial functional dependency, since the


dependent name is not a subset
of determinant roll_no. Similarly, {roll_no, name} → age is also a non-
trivial functional dependency, since age is not a subset of {roll_no,
name}
3. Multivalued Functional Dependency
In Multivalued functional dependency, entities of the dependent set
are not dependent on each other. i.e. If a → {b, c} and there exists no
functional dependency between b and c, then it is called a multivalued
functional dependency.
For example,
roll_no name age

42 abc 17

43 pqr 18

44 xyz 18
roll_no name age

45 abc 19

Here, roll_no → {name, age} is a multivalued functional dependency,


since the dependents name & age are not dependent on each
other(i.e. name → age or age → name doesn’t exist !)
4. Transitive Functional Dependency
In transitive functional dependency, dependent is indirectly dependent on
determinant. i.e. If a → b & b → c, then according to axiom of
transitivity, a → c. This is a transitive functional dependency.
For example,
enrol_no name dept building_no

42 abc CO 4

43 pqr EC 2

44 xyz IT 1

45 abc EC 2

Here, enrol_no → dept and dept → building_no. Hence, according to


the axiom of transitivity, enrol_no → building_no is a valid functional
dependency. This is an indirect functional dependency, hence called
Transitive functional dependency.
5. Fully Functional Dependency
In full functional dependency an attribute or a set of attributes uniquely
determines another attribute or set of attributes. If a relation R has
attributes X, Y, Z with the dependencies X->Y and X->Z which states that
those dependencies are fully functional.
6. Partial Functional Dependency
In partial functional dependency a non key attribute depends on a part of
the composite key, rather than the whole key. If a relation R has attributes
X, Y, Z where X and Y are the composite key and Z is non key attribute.
Then X->Z is a partial functional dependency in RBDMS.

Advantages of Functional Dependencies

Functional dependencies having numerous applications in the field of


database management system. Here are some applications listed below:
1. Data Normalization
Data normalization is the process of organizing data in a database in
order to minimize redundancy and increase data integrity. Functional
dependencies play an important part in data normalization. With the help
of functional dependencies we are able to identify the primary key,
candidate key in a table which in turns helps in normalization.
2. Query Optimization
With the help of functional dependencies we are able to decide the
connectivity between the tables and the necessary attributes need to be
projected to retrieve the required data from the tables. This helps in query
optimization and improves performance.
3. Consistency of Data
Functional dependencies ensures the consistency of the data by
removing any redundancies or inconsistencies that may exist in the data.
Functional dependency ensures that the changes made in one attribute
does not affect inconsistency in another set of attributes thus it maintains
the consistency of the data in database.
4. Data Quality Improvement
Functional dependencies ensure that the data in the database to be
accurate, complete and updated. This helps to improve the overall quality
of the data, as well as it eliminates errors and inaccuracies that might
occur during data analysis and decision making, thus functional
dependency helps in improving the quality of data in database.

Inference Rule (IR)/ Armstrong's axioms:


o The Armstrong's axioms are the basic inference rule.
o Armstrong's axioms are used to conclude functional dependencies on a
relational database.
o The inference rule is a type of assertion. It can apply to a set of FD(functional
dependency) to derive other FD.
o Using the inference rule, we can derive additional functional dependency from
the initial set.
The Functional dependency has 6 types of inference rule:

1. Reflexive Rule (IR1)


In the reflexive rule, if Y is a subset of X, then X determines Y.

1. If X ⊇ Y then X → Y
Example:

1. X = {a, b, c, d, e}
2. Y = {a, b, c}

2. Augmentation Rule (IR2)


The augmentation is also called as a partial dependency. In augmentation, if X determines
Y, then XZ determines YZ for any Z.

1. If X → Y then XZ → YZ
Example:

1. For R(ABCD), if A → B then AC → BC

3. Transitive Rule (IR3)


In the transitive rule, if X determines Y and Y determine Z, then X must also determine Z.

1. If X → Y and Y → Z then X → Z

4. Union Rule (IR4)


Union rule says, if X determines Y and X determines Z, then X must also determine Y and
Z.

1. If X → Y and X → Z then X → YZ
Proof:

1. X → Y (given)
2. X → Z (given)
3. X → XY (using IR2 on 1 by augmentation with X. Where XX = X)
4. XY → YZ (using IR2 on 2 by augmentation with Y)
5. X → YZ (using IR3 on 3 and 4)

5. Decomposition Rule (IR5)


Decomposition rule is also known as project rule. It is the reverse of union rule.

This Rule says, if X determines Y and Z, then X determines Y and X determines Z


separately.

1. If X → YZ then X → Y and X → Z
Proof:

1. X → YZ (given)
2. YZ → Y (using IR1 Rule)
3. X → Y (using IR3 on 1 and 2)

6. Pseudo transitive Rule (IR6)


In Pseudo transitive Rule, if X determines Y and YZ determines W, then XZ determines W.

1. If X → Y and YZ → W then XZ → W
Proof:

1. X → Y (given)
2. WY → Z (given)
3. WX → WY (using IR2 on 1 by augmenting with W)
4. WX → Z (using IR3 on 3 and 2)

Normalization
o Normalization is the process of organizing the data in the database.
o 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.
o Normalization divides the larger table into smaller and links them using
relationships.
o The normal form is used to reduce redundancy from the database table.
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. Normalization consists of a series of
guidelines that helps to guide you in creating a good database structure.
Data modification anomalies can be categorized into three types:

o Insertion Anomaly: Insertion Anomaly refers to when one cannot insert a


new tuple into a relationship due to lack of data.
o Deletion Anomaly: The delete anomaly refers to the situation where the
deletion of data results in the unintended loss of some other important data.
o Updatation Anomaly: The update anomaly is when an update of a single
data value requires multiple rows of data to be updated.

Types of Normal Forms:


Normalization works through a series of stages called Normal forms. The normal forms
apply to individual relations. The relation is said to be in particular normal form if it satisfies
constraints.

Following are the various types of Normal forms:


Normal Form Description

A relation is in 1NF if it contains an atomic


1NF
value.

A relation will be in 2NF if it is in 1NF and all


2NF non-key attributes are fully functional
dependent on the primary key.

A relation will be in 3NF if it is in 2NF and no


3NF
transition dependency exists.

A stronger definition of 3NF is known as


BCNF
Boyce Codd's normal form.

A relation will be in 4NF if it is in Boyce


4NF Codd's normal form and has no multi-valued
dependency.

A relation is in 5NF. If it is in 4NF and does


5NF not contain any join dependency, joining
should be lossless.

Advantages of Normalization

o Normalization helps to minimize data redundancy.


o Greater overall database organization.
o Data consistency within the database.
o Much more flexible database design.
o Enforces the concept of relational integrity.
Disadvantages of Normalization

o You cannot start building the database before knowing what the user needs.
o The performance degrades when normalizing the relations to higher normal
forms, i.e., 4NF, 5NF.
o It is very time-consuming and difficult to normalize relations of a higher
degree.
o Careless decomposition may lead to a bad database design, leading to
serious problems.

First Normal Form (1NF)


o A relation will be 1NF if it contains an atomic value.
o It states that an attribute of a table cannot hold multiple values. It must hold
only single-valued attribute.
o First normal form disallows the multi-valued attribute, composite attribute, and
their combinations.
o
Example: Relation EMPLOYEE is not in 1NF because of multi-valued attribute
EMP_PHONE.

EMPLOYEE table:

EMP_ID EMP_NAME EMP_PHONE EMP_STATE

7272826385,
14 John UP
9064738238

20 Harry 8574783832 Bihar

7390372389,
12 Sam Punjab
8589830302

The decomposition of the EMPLOYEE table into 1NF has been shown below:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385 UP

14 John 9064738238 UP

20 Harry 8574783832 Bihar

12 Sam 7390372389 Punjab

12 Sam 8589830302 Punjab

Second Normal Form (2NF)


o In the 2NF, relational must be in 1NF.
o In the second normal form, all non-key attributes are fully functional dependent on
the primary key
o A relation is in 2NF if it has no partial dependency, i.e., no non-prime
attribute (attributes that are not part of any candidate key), which is
dependent on any proper subset of any candidate key in the table

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.

TEACHER table

TEACHER_ID SUBJECT TEACHER_AGE

25 Chemistry 30
25 Biology 30

47 English 35

83 Math 38

83 Computer 38

In the given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID


which is a proper subset of a candidate key. That's why it violates the rule for 2NF.

To convert the given table into 2NF, we decompose it into two tables:

TEACHER_DETAIL table:

TEACHER_ID TEACHER_AGE

25 30

47 35

83 38

TEACHER_SUBJECT table:

TEACHER_ID SUBJECT

25 Chemistry

25 Biology
47 English

83 Math

83 Computer

Third Normal Form (3NF)


o A relation will be in 3NF if it is in 2NF and not contain any transitive partial
dependency.
o 3NF is used to reduce the data duplication. It is also used to achieve the data
integrity.
o 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.

1. X is a super key.
2. Y is a prime attribute, i.e., each element of Y is part of some candidate key.

Example:

EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY

222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago


555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal

EMPLOYEE_DETAIL table:

Super key in the table above:

1. {EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP}....so on


Candidate key: {EMP_ID}

Non-prime attributes: In the given table, all attributes except EMP_ID are non-
prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent


on EMP_ID. The non-prime attributes (EMP_STATE, EMP_CITY) transitively
dependent on super key(EMP_ID). It violates the rule of third normal form.

That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.

EMPLOYEE table:

EMP_ID EMP_NAME EMP_ZIP

222 Harry 201010

333 Stephan 02228

444 Lan 60007

555 Katharine 06389

666 John 462007


EMPLOYEE_ZIP table:

EMP_ZIP EMP_STATE EMP_CITY

201010 UP Noida

02228 US Boston

60007 US Chicago

06389 UK Norwich

462007 MP Bhopal

Boyce Codd normal form (BCNF)


o BCNF is the advance version of 3NF. It is stricter than 3NF.
o A table is in BCNF if every functional dependency X → Y, X is the super key
of the table.
o 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.

EMPLOYEE table:

EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DEPT_NO

264 India Designing D394 283

264 India Testing D394 300

364 UK Stores D283 232

364 UK Developing D283 549

In the above table Functional dependencies are as follows:

1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate key: {EMP-ID, EMP-DEPT}

The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.

To convert the given table into BCNF, we decompose it into three tables:

EMP_COUNTRY table:

EMP_ID EMP_COUNTRY

264 India
264 India

EMP_DEPT table:

EMP_DEPT DEPT_TYPE EMP_DEPT_NO

Designing D394 283

Testing D394 300

Stores D283 232

Developing D283 549

EMP_DEPT_MAPPING table:

EMP_ID EMP_DEPT

D394 283

D394 300

D283 232

D283 549

Functional dependencies:

1. EMP_ID → EMP_COUNTRY
2. EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:

Forthefirsttable: EMP_ID
Forthesecondtable: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}

Now, this is in BCNF because left side part of both the functional dependencies is a key.

Fourth normal form (4NF)


o A relation will be in 4NF if it is in Boyce Codd normal form and has no multi-
valued dependency.
o For a dependency A → B, if for a single value of A, multiple values of B exists,
then the relation will be a multi-valued dependency.

Example
STUDENT

STU_ID COURSE HOBBY

21 Computer Dancing

21 Math Singing

34 Chemistry Dancing

74 Biology Cricket

59 Physics Hockey

The given STUDENT table is in 3NF, but the COURSE and HOBBY are two independent
entity. Hence, there is no relationship between COURSE and HOBBY.

In the STUDENT relation, a student with STU_ID, 21 contains two


courses, Computer and Math and two hobbies, Dancing and Singing. So there is a Multi-
valued dependency on STU_ID, which leads to unnecessary repetition of data.

So to make the above table into 4NF, we can decompose it into two tables:
STUDENT_COURSE

STU_ID COURSE

21 Computer

21 Math

34 Chemistry

74 Biology

59 Physics

STUDENT_HOBBY

STU_ID HOBBY

21 Dancing

21 Singing

34 Dancing

74 Cricket

59 Hockey
Fifth Normal Form (5NF)
• A Relation is said to be in 5NF if both conditions are satisfied.
1) Relation should be already in 4NF
2) It cannot be further non-loss decomposed (Join Dependency should
not be present)
• The Fifth Normal Form (5NF) is also known as the Project-Join Normal
Form (PJNF).
• 5NF gets satisfied when the table is broken down into as many parts as
possible to avoid data redundancy.

Let’s have a look at the above 2 conditions for 5NF.


Relation Should be Already in 4NF
• It should satisfy all the conditions of 4NF i.e
1. It should be in BCNF.
2. No multi-valued dependency should exist.
Non-Loss Decomposition
• When the table does not contain any join dependency then it is called a
lossless /non-loss decomposition.
• In other words, we can say that
• A database is in 5NF when there is no join dependency present in the
table / database.
• When we decompose the given table to remove redundancy in the data
and then compose it again to create the original table , we should not
lose any data, and the original table should be obtained as a loss
should happen after the decomposition of the table.
• Join dependency for relation R can be stated as
• R=(R1 ⨝ R2 ⨝ R3 ⨝ ………Rn) where R1,R2,R3…..Rn are sub-
relation of R and ⨝ is Natural Join Operator.
• Here R1, R2, R3, ….Rn are the sub-relation of relation R.
Example
• let’s, take of Table R which has 3 columns i.e. subject, class, and
teacher where each subject can be taught by many teachers in many
classes, and a teacher can teach more than 1 subject.
Subject Class Teacher

math class 10 kartik

math class 9 yash

math class 10 yash

science class 10 yash

• Here the subject of math is taught by both teachers kartik and yash.
Also yash can teach math and science. Yash teaches math to both
class 9 and class 10.
• As there is redundancy in data we will decompose it into two tables R1
and R2 such that R1 will have attribute Subject and Class and R2 will
have attribute class and teacher.
Table R1
Subject Class

math class 9

math class 10

science class 10

• Here we removed the redundancy in the table by removing the extra


tuple with the same values i.e. subject math taught in class 10. This
tuple is repeated 2 times in the main table but in table R1 this
redundancy is removed.
Table R2
Class Teacher

class 10 kartik

class 9 yash
Class Teacher

class 10 yash

• Here we removed the redundancy in the table by removing the extra


tuple with the same values i.e. yash is teaching for class 10. This tuple
is repeated 2 times in the main table but in table R2 this redundancy is
removed.
• After combining both tables R1 and R2 we will get as mentioned below:
Table (R1 ⨝ R2)
Subject Class Teacher

math class 9 yash

math class 10 kartik

math class 10 yash

science class 10 kartik

science class 10 yash

• Here if we notice the newly composed table from R1 and R2 and the
original table, an extra tuple is added that did not exist in the original
data, This breaks the second rule of 5NF i.e. non-loss
decomposition.
• This type of unwanted tuple is known as Spurious tuple.
• Here we will decompose the given table in another relation R3 where it
will have 2 columns i.e. subject and teacher.
Table R3
Subject Teacher

math yash

math kartik
Subject Teacher

science yash

• Here the newly decomposed table R3 will have 3 tuples only as the
repeated tuple (redundancy ) is not added to the table. yash teaching
the subject math is repeated 2 times in main table R but here it will be
added only one time resulting in removing the redundancy in the table.
• Now if we compose or rejoin the tables R1, R2, and R3 we will get
Table (R1 ⨝ R2⨝ R3)
Subject Class Teacher

math class 9 yash

math class 10 yash

math class 10 kartik

science class 10 yash

• Now if we see the re-composed table and the original table, there is no
loss of data.
• Here all the tables, R1, R2 and R3 had a natural join which resulted in
the table R. After the natural join, the original table is retained as it is.
There is no loss of the data.
• So it is atables
• Given Table R1, R2 and R3 are in the Fifth Normal Form(5NF).
Uses of Fifth Normal Form(5NF)
• 5NF ensures that there will be no redundancy present in the database.
Removing the redundancy in the database helps the data to remain
more optimized and easy to perform database actions.
• It also ensures that there will be non-lossy decomposition only which
will result in data consistency and data integrity.
• As data redundancy and anomalies are removed, the database
performance gets enhanced.
Limitation of Fifth Normal Form(5NF)
• One of the biggest limitationsis of 5Nf is the complexity of the
database. Due to 5Nf large number of tables and relation gets created
which eventually increases the complexity of the database.
• Slow exhibition due to large number of tables.
• The cost of implementation of 5NF is also high as it increases the
complexity of the database.

Relational Decomposition
o When a relation in the relational model is not in appropriate normal form then
the decomposition of a relation is required.
o In a database, it breaks the table into multiple tables.
o If the relation has no proper decomposition, then it may lead to problems like
loss of information.
o Decomposition is used to eliminate some of the problems of bad design like
anomalies, inconsistencies, and redundancy.

Types of Decomposition

Lossless Decomposition

o If the information is not lost from the relation that is decomposed, then the
decomposition will be lossless.
o The lossless decomposition guarantees that the join of relations will result in
the same relation as it was decomposed.
o The relation is said to be lossless decomposition if natural joins of all the
decomposition give the original relation.
Example:

EMPLOYEE_DEPARTMENT table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME

22 Denim 28 Mumbai 827 Sales

33 Alina 25 Delhi 438 Marketing

46 Stephan 30 Bangalore 869 Finance

52 Katherine 36 Mumbai 575 Production

60 Jack 40 Noida 678 Testing

The above relation is decomposed into two relations EMPLOYEE and DEPARTMENT

EMPLOYEE table:

EMP_ID EMP_NAME EMP_AGE EMP_CITY

22 Denim 28 Mumbai

33 Alina 25 Delhi

46 Stephan 30 Bangalore
52 Katherine 36 Mumbai

60 Jack 40 Noida

DEPARTMENT table

DEPT_ID EMP_ID DEPT_NAME

827 22 Sales

438 33 Marketing

869 46 Finance

575 52 Production

678 60 Testing

Now, when these two relations are joined on the common column "EMP_ID", then the
resultant relation will look like:

Employee ⋈ Department

EMP_ID EMP_NAME EMP_AGE EMP_CITY DEPT_ID DEPT_NAME

22 Denim 28 Mumbai 827 Sales

33 Alina 25 Delhi 438 Marketing

46 Stephan 30 Bangalore 869 Finance


52 Katherine 36 Mumbai 575 Production

60 Jack 40 Noida 678 Testing

Hence, the decomposition is Lossless join decomposition.

Dependency Preserving

o It is an important constraint of the database.


o In the dependency preservation, at least one decomposed table must satisfy
every dependency.
o If a relation R is decomposed into relation R1 and R2, then the dependencies
of R either must be a part of R1 or R2 or must be derivable from the
combination of functional dependencies of R1 and R2.
o For example, suppose there is a relation R (A, B, C, D) with functional
dependency set (A->BC). The relational R is decomposed into R1(ABC) and
R2(AD) which is dependency preserving because FD A->BC is a part of
relation R1(ABC).

Multivalued Dependency
o Multivalued dependency occurs when two attributes in a table are
independent of each other but, both depend on a third attribute.
o A multivalued dependency consists of at least two attributes that are
dependent on a third attribute that's why it always requires at least three
attributes.
Example: Suppose there is a bike manufacturer company which produces two colors(white
and black) of each model every year.

BIKE_MODEL MANUF_YEAR COLOR

M2011 2008 White

M2001 2008 Black


M3001 2013 White

M3001 2013 Black

M4006 2017 White

M4006 2017 Black

Here columns COLOR and MANUF_YEAR are dependent on BIKE_MODEL and


independent of each other.

In this case, these two columns can be called as multivalued dependent on BIKE_MODEL.
The representation of these dependencies is shown below:

1. BIKE_MODEL → → MANUF_YEAR
2. BIKE_MODEL → → COLOR
This can be read as "BIKE_MODEL multidetermined MANUF_YEAR" and "BIKE_MODEL
multidetermined COLOR".

Closure of an Attribute
Closure of an Attribute: Closure of an Attribute can be defined as a set of attributes that
can be functionally determined from it.

OR

Closure of a set F of FDs is the set F+ of all FDs that can be inferred from F

Closure of a set of attributes X concerning F is the set X+ of all attributes that are
functionally determined by X.

Pseudocode to find Closure of an Attribute?


Determine X+, the closure of X under functional dependency set F

X Closure : = will contain X itself;

Repeat the process as:

old X Closure : = X Closure;

for each functional dependency P → Q in FD set do


if X Closure is subset of P then X Closure := X Closure U Q ;

Advertisement

Repeat until ( X Closure = old X Closure);

Algorithm of Determining X+, the Closure of X under F


Input: A set F of FDs on a relation schema R, and a set of attributes X, which is a subset of
R.

1. X+ := X;
2. repeat
3. oldX+ := X+ ;
4. for each functional dependency Y → Z in F do
5. if X+ ⊇ Y then X+ := X+ ∪ Z;
6. until (X+ = oldX+ );

QUESTIONS ON CLOSURE SET OF ATTRIBUTE:


1) Given relational schema R( P Q R S T U V) having following attribute P Q R S T U and V,
also there is a set of functional dependency denoted by FD = { P->Q, QR->ST, PTV->V }.

Determine Closure of (QR)+ and (PR)+

a) QR+ = QR (as the closure of an attribute or set of attributes contain same).

Now as per algorithm look into a set of FD that complete the left side of any FD contains
either Q, R, or QR since in FD QR→ST has complete QR.

Hence QR+ = QRST

Again, trace the remaining two FD that any left part of FD contains any Q, R, S, T.

Since no complete left side of the remaining two FD{P->Q, PTV->V} contain Q, R, S, T.

Therefore QR+ = QRST (Answer)

Note: In FD PTV→V, T is in QRST but that cannot be entertained, as complete PTV


should be a subset of QRST
b) PR + = PR (as the closure of an attribute or set of attributes contain same)

Now as per algorithm look into a set of FD, and check that complete left side of any FD
contains either P, R, or PR. Since in FD P→Q, P is a subset of PR, Hence PR+ = PRQ
Again, trace the remaining two FD that any left part of FD contains any P, R, Q, Since, in
FD QR → ST has its complete left part QR in PQR

Hence PR+ = PRQST

Again trace the remaining one FD { PTV->V } that its complete left belongs to PRQST.
Since complete PTV is not in PRQST, hence we ignore it.

Therefore PR+ = PRQST ( Answer)

2. Given relational schema R( P Q R S T) having following attributes P Q R S and T, also


there is a set of functional dependency denoted by FD = { P->QR, RS->T, Q->S, T-> P }.

Determine Closure of ( T )+

T + = T (as the closure of an attribute or set of attributes contain same) Now as per
algorithm look into a set of FD that complete the left side of any FD contains T since, in FD
T → P, T is in T, Hence T+ = TP Again trace the remaining three FD that any left part of FD
contain any TP, Since in FD P → QR has its complete left part P in TP, Hence T+ = TPQR
Again trace the remaining two FD { RS->T, Q->S } that any of its Complete left belongs to
TPQR, Since in FD Q → S has its complete left part Q in TPQR, Hence T+ = TPQRS Again
trace the remaining one FD { RS->T } that its complete left belongs to TPQRS, Since in FD
RS → T has its complete left part RS in TPQRS Hence T+ = TPQRS ( no changes, as T, is
already in TPQRS) Therefore T+ = TPQRS ( Answer).

Canonical Cover
In database management systems (DBMS), a canonical cover is a set of
functional dependencies that is equivalent to a given set of functional
dependencies but is minimal in terms of the number of dependencies. The
process of finding the canonical cover of a set of functional dependencies
involves three main steps:
• Reduction: The first step is to reduce the original set of functional
dependencies to an equivalent set that has the same closure as the
original set, but with fewer dependencies. This is done by removing
redundant dependencies and combining dependencies that have
common attributes on the left-hand side.
• Elimination: The second step is to eliminate any extraneous attributes
from the left-hand side of the dependencies. An attribute is considered
extraneous if it can be removed from the left-hand side without
changing the closure of the dependencies.
• Minimization: The final step is to minimize the number of
dependencies by removing any dependencies that are implied by other
dependencies in the set.
Illustrative Example
Consider a set of Functional dependencies: 𝐹={𝐴→𝐵𝐶,𝐵→𝐶,𝐴𝐵→𝐶}. Here
are the steps to find the canonical cover –
Step 1:Decompose FDs to have a single attribute on the right-hand
side
• 𝐴→𝐵𝐶 becomes 𝐴→𝐵 and 𝐴→𝐶.
• Therefore, we have {𝐴→𝐵, 𝐴→𝐶, 𝐵→𝐶, 𝐴𝐵→𝐶}.
Step 2:Remove extraneous attributes from the left-hand side of
FDs
• Checking 𝐴𝐵→𝐶: First, check if 𝐴 or 𝐵 is extraneous.
• We can reach 𝐶 without using 𝐴𝐵→𝐶 with other functional
dependencies; therefore, we remove 𝐴𝐵→𝐶.
• Finally, we have {𝐴→𝐵, 𝐴→𝐶, 𝐵→𝐶}.
Step 3:Remove redundant FDs
• Check each functional dependency to see if it can be reached without
using it. For example, 𝐴→𝐶 can be reached with 𝐴→𝐵 and 𝐵→𝐶.
Therefore, 𝐴→𝐶 is redundant and can be removed.
• Hence, Canonical Cover = {𝐴→𝐵, 𝐵→𝐶}.

How to Find Canonical Cover


To compute the canonical cover for set F, follow this algorithm –
• Use the union rule to replace any dependencies in α1 → β1 and α2 →
β2 with α1 → β1β2.
• Find a functional dependency α → β with an extraneous attribute either
in α or in β.
• If an extraneous attribute is found, delete it from α → β.
• Repeat until F does not change.
Example 1
Given F = { A → BC, B → C, A → B, AB → C }
• Step 1 Reduction: There are two functional dependencies with the
same attributes on the left: A → BC, A → B are already in their
simplest form.
• Step 2 Elimination: In A → BC, C is extraneous because A → C can
be derived from A → B and B → C. Thus, we reduce it to A → B.
• Step 3 Minimization: No redundant dependencies remain.
Hence, the canonical cover is Fc = { A → B, B → C }
Example 2
Given F = { A → BC, CD → E, B → D, E → A }
• Step 1 Reduction: Each left-hand side of the functional dependencies
is unique and cannot be combined further.
• Step 2 Elimination: None of the attributes on the left or right sides of
any functional dependency are extraneous.
• Step 3 Minimization: No dependencies are redundant.
Hence, the canonical cover is F = { A → BC, CD → E, B → D, E → A }
How to Check Whether a Set of FD’s F Canonically
Covers Another Set of FD’s G?
Consider the following two sets of functional dependencies: F = { A → B,
AB → C, D → A, CD → E } G = { A → B, CD → AB } Now, we are required
to find out whether one of these f.d.’s canonically covers the other set of
f.d.’s. This means, we need to find out whether F canonically covers G, G
canonically covers F, or none of the two canonically cover the other. To
find out, we follow the following steps:
• Create a singleton right-hand side. This means the attributes to the
right side of the f.d. arrow should all be a singleton. All the ride side is
single. So, F = { A → B, AB → C, D → A, CD → E }
• Remove all extraneous attributes. Consider any functional dependency
XY → Z. If X in itself can determine Z, then the attribute Y is
extraneous and can be removed. As we can see, the occurrence of
extraneous attributes is possible only in those functional dependencies
where there is more than one attribute in the LHS. So, consider the
functional dependency AB → C. Now, we must find the closures of A
and B to find whether any of these is extraneous. [A]+=ABC, [B]+=B As
we can see, C can be determined from A. This means we can remove
B from the functional dependency AB → C. F = { A → B, A → C, D →
A, CD → E }
• Remove all redundant functional dependencies. Check all f.d.’s one by
one, and see if by removing an f.d. X → Y, we can still find out Y from
X by some other f.d. A more formal way to state this finds [X]+ without
making use of the f.d. we are testing and check whether Y is a part of
the closure. If yes, then the f.d. is redundant. No f.d can be removed in
this step. So, final F = { A → B, A →C, D → A , CD → E } or, F = { A →
BC, D → A , CD → E }.
Now, checking G this time
• Create a singleton right-hand side. This means the attributes to the
right side of the f.d. arrow should all be a singleton. G = { A → B, CD →
A, CD → B }
• Remove all extraneous attributes. Since the RHS of all f.d.’s contains
only 1 attribute, no extraneous attribute is possible.
• Remove all redundant functional dependencies. By looping over all
f.d.’s and checking the closure of the LHS in all cases, we observe that
the f.d. CD → B is redundant as it can be obtained through a
combination of 2 other f.d.’s, CD → A and A → B. So, final G = { A →
B, CD → A }
Now, since all f.d.’s of G are not covered in F, we conclude that F does
not cover G.
Features of the Canonical Cover
• Minimal: The canonical cover is the smallest set of dependencies that
can be derived from a given set of dependencies, i.e., it has the
minimum number of dependencies required to represent the same set
of constraints.
• Lossless: The canonical cover preserves all the functional
dependencies of the original set of dependencies, i.e., it does not lose
any information.
• Deterministic: The canonical cover is deterministic, i.e., it does not
contain any redundant or extraneous dependencies.
• Reduces Data Redundancy: The canonical cover helps to reduce
data redundancy by eliminating unnecessary dependencies that can be
inferred from other dependencies.
• Improves Query Performance: The canonical cover helps to improve
query performance by reducing the number of joins and redundant data
in the database.
• Facilitates Database Maintenance: The canonical cover makes it
easier to modify, update, and delete data in the database by reducing
the number of dependencies that need to be considered.

You might also like