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

Unit 5

The document covers the concepts of relational database design, focusing on functional dependencies, keys, normalization, and database anomalies. It explains various types of functional dependencies, including trivial and non-trivial, as well as the significance of super keys, candidate keys, and primary keys. Additionally, it discusses normalization processes, types of anomalies (insert, delete, update), and provides examples and short questions for further understanding of the topics.

Uploaded by

Priyanshu Verma
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)
9 views

Unit 5

The document covers the concepts of relational database design, focusing on functional dependencies, keys, normalization, and database anomalies. It explains various types of functional dependencies, including trivial and non-trivial, as well as the significance of super keys, candidate keys, and primary keys. Additionally, it discusses normalization processes, types of anomalies (insert, delete, update), and provides examples and short questions for further understanding of the topics.

Uploaded by

Priyanshu Verma
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/ 41

Faculty of Engineering and Technology

Parul Institute of Technology


Department of Computer Science & Engineering
Course: B.Tech – CSE
Subject: Database Management System
Unit 5
Relational Database Design
:Overview:
• What is Functional Dependency? • Database Anomalies
• Trivial Functional Dependency • Insert Anomalies
• Non-Trivial Functional Dependency
• Delete Anomalies
• Super Key • Update Anomalies
• Candidate Key • Normalization
• Primary Key • 1 NF
• Armstrong Rules • 2 NF
• 3 NF
• Closure of Functional Dependency Set and Closure of Attributes
• BCNF
• How to find super key using Closure of Attributes?
• Examples of Normalization
• Examples - How to find super key and candidate key
• Functional Dependency Preserving Decomposition
• Lossless Join & Lossy Join Decomposition
• Examples on Decomposition
What is Functional Dependency?
• Let R be a relation schema having attributes X and Y.
• If the values of the X determine the values of the Y, 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.

ID Name Department Salary There are following possible functional dependencies for
1 A CSE 30000 the given relation:

2 B EE 35000 ID -> Name


4 C MT 53000 ID -> Department
5 D ME 18000 ID -> Salary
ID -> Name, Department, Salary
8 D ASH 45000 ID, Name -> Department, Salary
9 F CE 63000 Name, Department -> Salary
What is Functional Dependency?
• Let R be a relation schema having attributes X and Y.
• If the values of the X determine the values of the Y, 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.

ID Name Department Salary Think about the following functional dependencies. Is it


1 A CSE 30000 possible to define like this?

2 B EE 35000 Name -> Department


4 C MT 53000 Name -> Salary
5 D ME 18000
8 D ASH 45000
9 F CE 63000
:Trivial Functional Dependency:
• X→Y is trivial Functional Dependency if Y is a subset of X.
• For Example:
ID, Name -> Name, Department, Salary
ID, Name -> Name
ID, Department -> Department, Salary
:Non Trivial Functional Dependency:
• X→Y is non- trivial Functional Dependencies if there is no common
attribute in X, Y attribute set.
• For Example:
ID -> Name
ID -> Department
ID -> Salary
ID -> Name, Department, Salary
:Super Key:
• An attribute or a group of attributes that can uniquely retrieve all the
attributes of a relation, is known as “Super Key”.
• There may be one or more than one super keys possible for a relation.

ID -> ID, Name, Department, Salary


ID, Name -> ID, Name, Department, Salary
ID, Name, Department -> ID, Name, Department, Salary
ID, Name, Department, Salary -> ID, Name, Department, Salary
Department -> ID, Name, Department, Salary
Department, ID -> ID, Name, Department, Salary
Department, ID, Salary -> ID, Name, Department, Salary
Salary -> ID, Name, Department, Salary
:Candidate Key:
• Minimal super key is known as “Candidate Key”.
• There may be one or more than one candidate keys possible for a
relation.
• All the Candidate Keys are Super Key but All the Super Keys can not be Candidate Key.
ID -> ID, Name, Department, Salary
Department -> ID, Name, Department, Salary
Salary -> ID, Name, Department, Salary
:Primary Key:
• An attribute that uniquely identifies or retrieve all the attributes of a
relation is known as “Primary Key”. A table can only have one primary
key. It doesn’t permit null values.

ID -> ID, Name, Department, Salary


Department -> ID, Name, Department, Salary
Salary -> ID, Name, Department, Salary
:Armstrong Rules:
• Armstrong's axioms are a set of rules used to derive all the functional dependencies on a relational
database.
• Let A, B, and C is subsets of the attributes of the relation R.
• Rules are given here based on following figure:
:Closure of Functional Dependency Set/Closure of Attributes:

• For given set of attributes, the closure of any attribute X under Functional
Dependency F, is the set of attributes that are functionally determined by X under
F.
• It is denoted by X+.

[X]+ = {Set of attributes determined by X}


:Closure of Functional Dependency Set/Closure of Attributes:

• For given set of attributes, the closure of any attribute X under Functional Dependency F, is the set of attributes that are
functionally determined by X under F.
• It is denoted by X+.
[X]+ = {Set of attributes determined by X}

Example:
Given relation R with attributes A,B,C,D,E,F,G and set of Functional Dependencies,
F = { A → B, B → C, AC → D, CD → E, G → A, AF → G }.
Find the Closure of A and AF.

Solution:
A+ ={ A, B, C, D, E)
[AF]+ = {A, B, C, D, E, F, G}
How to find super key using Closure of Attributes?
• X is a Super Key of R if X+ should determine all the attribute of Relation R.

Example:
R(ABCD), F = { A → B, B → C, C → D }
[A]+ = {A, B, C, D}
Hence, A is one of the super keys.
:Functional Dependency Preserving Decomposition:

• Let R be the Relational schema with functional dependency set F is decomposed into R1, R2,
R3…Rn sub relations with functional dependency set F1, F2, F3,...Fn respectively.

• If [F1 ∪ F2 ∪ F3 ∪…… Fn] = F then it is dependency preserving decomposition.


• If [F1 ∪ F2 ∪ F3 ∪…… Fn] ⊂ F then it is not dependency preserving decomposition.
:Lossless Join and Lossy Join Decomposition:

• Relational schema R with Functional Dependency Set F decomposed into R1 & R2 decomposition is lossless
if and only if all of the following conditions satisfy.
1. R1 ∩ R2 → R1 or R2
2. R1∪ R2 = R
3. R1 ∩ R2 = NULL
:Database Anomalies:
• Anomalies are problems that can occur in poorly planned,
un-normalized database where all the data are stored in one table.
• Anomalies lead to data redundancy and inconsistency. So it is
required to be eliminated.

Anomalies

Insert Delete Update


Anomalies Anomalies Anomalies
:Database Anomalies:
:Insert Anomalies:
• Let us assume that a new course has been started by the Institute but initially there are no
students enrolled for that course. Then the tuple for this course cannot be inserted in to this table
as the Sid will have NULL value, which is not allowed because Sid is primary key. This is known as
Insert Anomalies.
:Delete Anomalies:
• Now consider there is one student in and that student leaves the Institute. Then the tuple of that
student has to be deleted from the table, but in addition to that information about the course also
will be deleted.
• This kind of problem in the relation where deletion of some tuples can lead to loss of some other
data not intended to be removed is known as Delete Anomalies.
:Update Anomalies:
• Suppose the fees of a course have changed, this requires that the course in all the tuples
corresponding to that course must be changed to reflect the new status. If we fail to update all
the tuples of given course, then two different records of the student enrolled in the same course
might show different fees which leads to inconsistency in the database. This is known as Update
Anomalies.
:Normalization:
• Normalization is a method to organize the data to prevent redundancy.
• It is used to structure the tables in such a way that logical inconsistencies and
anomalies can be removed.
:1 NF:
• Relational schema R is in 1 NF if no multivalued attribute in Relation R. Every attribute of relation R must be
single valued. Default NF is 1 NF.
• Consider the following relation. It is difficult to retrieve the list of customers living in ‘Vadodara’ from the
table. Reason is address attribute is composite attribute which contains name of the area as well as city
name in single cell.

• To solve the particular problem, divide composite attributes into number of sub- attribute and insert value in
proper sub attribute. This way, we can get the following table which is in 1 NF.
:Short Questions:
1. What is Functional Dependency? Explain with a suitable example.
2. What is Trivial Functional Dependency? Explain with a suitable example.
3. What is Non-Trivial Functional Dependency? Explain with a suitable example.
4. Define:
A. Super Key
B. Candidate Key
C. Primary Key
D. Closure of Attribute

5. What is Functional Dependency Preserving Decomposition?


6. What is Lossy Join Decomposition?
7. What is Lossless Join Decomposition? What are the conditions to be fulfilled for Lossless Join
Decomposition?
:Short Questions:
8. Define Anomalies. What are the types of anomalies?
9. Explain Insert Anomalies with a suitable example.
10. Explain Delete Anomalies with a suitable example.
11. Explain Update Anomalies with a suitable example.
12. Define Normalization. Enlist types of Normal Forms.
13. Explain 1 NF with a suitable example.
14. What are the conditions for a relation to be in 2 NF?
15. What are the conditions for a relation to be in 3 NF?
16. What do you mean by BCNF? What are the conditions for a relation to be in BCNF?

You might also like