0% found this document useful (0 votes)
4 views44 pages

Lecture - 15&16 - Functional Dependency

Uploaded by

zoya351344
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 views44 pages

Lecture - 15&16 - Functional Dependency

Uploaded by

zoya351344
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/ 44

Relational Databases

Normalization and
Functional dependency
Normalization

❑ Normalization is a technique for producing a


set of suitable relations that support the data
requirements of an enterprise.

2
Purpose of Normalization

◼ Characteristics of a suitable set of


relations include:
❑ The minimal number of attributes necessary to
support the data requirements of the enterprise;

❑ Attributes with a close logical relationship are


found in the same relation;

3
Purpose of Normalization
❑ The benefits of using a database that has a
suitable set of relations is that the database will
be:
❑ Easier for the user to access and maintain the
data;
❑ Take up minimal storage space on the computer.

4
Data Redundancy and Update
Anomalies

❑ Major aim of relational database design is to


group attributes into relations to minimize data
redundancy.

5
Data Redundancy and Update
Anomalies

❑ Problems associated with data redundancy are


illustrated by comparing the Staff and Branch
relations with the Staff Branch relation.

6
7
Data Redundancy and Update
Anomalies

8
Data Redundancy and Update
Anomalies
❑ Staff Branch relation has redundant data; the
details of a branch are repeated for every member
of staff.

❑ In contrast, the branch information appears only


once for each branch in the Branch relation and
only the branch number (branch No) is repeated
in the Staff relation, to represent where each
member of staff is located.

9
Data Redundancy and Update
Anomalies
❑ Relations that contain redundant information may
potentially suffer from update anomalies.

❑ Types of update anomalies include


❑ Insertion
❑ Deletion
❑ Modification

10
Normalization

◼ It is a technique to remove or reduce


redundancy from a table .
◼ It is very important topic in DBMS
◼ There are basically two types of duplicacy in
tables in database
❑ Row level
❑ Column level
Normalization

◼ Row level duplicacy –


❑ Relation (Student )

Sid Name Age

1 sara 20

2 ali 30

1 Sara 20

12
Normalization –column level duplicacy

Sid Snam cid Cname Fid Fname Salary


e
1 Ali C1 DB F1 Maryam 30000
2 Sara C2 DB F2 Ahad 20000

3 sana C1 DB F1 Maryam 30000

4 Zohaib C1 DB F1 Maryam 30000

5 Anum C1 DB F1 Bushra 60000

6 Irha C1 DB F1 Saira 50000

13
Problems

◼ So basically, problems comes in three types


❑ Insertion anomaly
❑ Deletion anomaly
❑ Updation anomaly

◼ So how these problems would be resolved by


normalization( we will discuss later)
◼ Simple solution
❑ To divide the table in multiple tables
14
15
Solution
CID Cname
c1 Db
c2 DB1

FID F-name Salary

F1 maryam 30000

F2 Ahad 20000

F3 Bushra 50000

F4 Saira 60000

16
Functional Dependencies
◼ Important concept associated with normalization.

◼ Functional dependency describes relationship


between attributes.

◼ For example, if A and B are attributes of relation R, B


is functionally dependent on A (denoted A → B), if
each value of A in R is associated with exactly one
value of B in R.

17
Functional dependency
An Example Functional
Dependency

19
Functional dependency

20
21
22
FD-Example

23
Types of FD

24
Fully FD

25
Is fully dependent /not ??

26
Partial FD

◼ A FD x y is a partial dependency if some


attribute A in x can be removed from x and
dependency still hold .
❑ (Name , ID ) course

27
FFD example :

◼ Student relation :

Name
Roll no

Grades

Games Fees

28
FFD /PFD

◼ Y is functionally ◼ Y is functionally
dependent on x and dependent on x and

◼ Y is not functionally ◼ Y can be determined


dependent on any by any subset of x
subset of x .

29
Functional Dependencies
Trivial Functional dependency

31
Trivial and Non -trivial FD

◼ A B&B A ◼ A B&B A
❑ A A ❑ A C
❑ B B ❑ AB D

◼ AB B
❑ A A
❑ B B

32
Non-trivial FD

33
Transitive and non- Transitive
FDS
◼ Transitive : X Y and Y Z then X Z
❑ Ssid sname and sname city
sid city
Roll no Semester Name
Semester Hostel
X
Roll no Hostel (TFD) Roll no
Roll no Name (NTF) Semester
Y
Roll no Semester(NTF)
Hostel
Z
◼ It is due to the dependency between non -PK in relation
.
34
Properties of FD

◼ Reflexive X Y XՈY≠ᵠ
◼ Augmentation: if X Y , then XZ YZ
Ssid Sname
Ssid ,phone no Sname ,Phone no

35
Properties of FD

◼ Union : If X Y and X Z then X YZ


◼ Decomposition :
❑ X YZ
Then X Y and X Z

36
Closure method (Example 1 )

◼ This method will help out to find all possible


candidate keys from the table .
◼ R(A,B,C,D)
❑ FD{A B, B C, C D}
◼ A+ =BCDA
◼ B+ =BCD
Ck = {A}
◼ C+= CD PA = A
◼ D+= D Non PA = BCD

◼ Primary attribute : which are used in formation of CK


37
Closure method (Example 2 )

◼ R(A,B,C,D)
❑ FD{A B,B C ,C D,D A}
◼ A+ =ABCD
◼ B+ =BCDA
◼ C+= CDAB
◼ D+= DABC
CK ={A,B ,C ,D }
PA =(A,B ,C ,D )
NON PA = ᶲ

38
Closure method (Example 3 )

◼ R(A,B,C,D,E)
❑ FD{A B , BC D ,E C,D A}
❑ AE+ = AEBCD
❑ DE+ =BEABC
❑ BE+ =BECDA
❑ CE+ =CE CK= { AE,BE,DE}
PA = { A,B,D,E}
NPA =C

39
Example - Using sample data to
identify functional dependencies.
and ck . Also find PA and NPA

40
Example - Using sample data to
identify functional dependencies.

41
Example - Using sample data to
identify functional dependencies.
◼ Function dependencies between
attributes A to E in the Sample relation.

A→C (fd1)
C→A (fd2)
B →D (fd3)
A, B → E (fd4)

42
Normalization ---Decomposition

◼ Two important properties of decomposition.


❑ Lossless-join property enables us to find any
instance of the original relation from
corresponding instances in the smaller relations.
❑ Dependency preservation property enables us
to enforce a constraint on the original relation by
enforcing some constraint on each of the smaller
relations.

43
44

You might also like