SlideShare a Scribd company logo
1
Lecture 6:
Schema refinement: Functional
dependencies
www.cl.cam.ac.uk/Teaching/current/Databases/
2
Recall: Database design
lifecycle
• Requirements analysis
– User needs; what must database do?
• Conceptual design
– High-level description; often using E/R model
• Logical design
– Translate E/R model into relational schema
• Schema refinement
– Check schema for redundancies and anomalies
• Physical design/tuning
– Consider typical workloads, and further optimise
Next
two
lectures
3
Today’s lecture
• Why are some designs bad?
• What’s a functional dependency?
• What’s the theory of functional
dependencies?
• (Next lecture: How can we use this theory
to classify redundancy in relation design?)
4
Not all designs are
equally good
• Why is this design bad?
Data(sid,sname,address,cid,cname,grade)
• Why is this one preferable?
Student(sid,sname,address)
Course(cid,cname)
Enrolled(sid,cid,grade)
5
An instance of our bad
design
sid sname addres
s
ci
d
cname grade
124 Britney USA 206 Database A++
204 Victoria Essex 202 Semantics C
124 Britney USA 201 S/Eng I A+
206 Emma London 206 Database B-
124 Britney USA 202 Semantics B+
6
Evils of redundancy
• Redundancy is the root of many problems associated with
relational schemas
– Redundant storage
– Update anomalies
– Insertion anomalies
– Deletion anomalies
– LOW TRANSACTION THROUGHPUT
• In general, with higher redundancy, if transactions are
correct (no anomalies), then they have to lock more objects
thus causing greater contention and lower throughput
• (Aside: Could having a dummy value, NULL, help?)
7
Decomposition
• We remove anomalies by replacing the schema
Data(sid,sname,address,cid,cname,grade)
with
Student(sid,sname,address)
Course(cid,cname)
Enrolled(sid,cid,grade)
• Note the implicit extra cost here
• Two immediate questions:
1. Do we need to decompose a relation?
2. What problems might result from a decomposition?
8
Functional dependencies
• Recall:
– A key is a set of fields where if a pair of tuples
agree on a key, they agree everywhere
• In our bad design, if two tuples agree on
sid, then they also agree on address,
even though the rest of the tuples may not
agree
9
Functional dependencies
cont.
• We can say that sid determines address
– We’ll write this
sid  address
• This is called a functional dependency
(FD)
• (Note: An FD is just another integrity
constraint)
10
Functional dependencies
cont.
• We’d expect the following functional
dependencies to hold in our Student database
– sid  sname,address
– cid  cname
– sid,cid  grade
• A functional dependency X  Y is simply a
pair of sets (of field names)
– Note: the sloppy notation A,B  C,D rather than
{A,B}  {C,D}
11
Formalities
• Given a relation R=R(A1:1, …, An:n), and X, Y
({A1, …, An}), an instance r of R satisfies
XY, if
– For any two tuples t1, t2 in R, if t1.X=t2.X then
t1.Y=t2.Y
• Note: This is a semantic assertion. We can
not look at an instance to determine which FDs
hold (although we can tell if the instance does
not satisfy an FD!)
12
Properties of FDs
• Assume that X  Y and Y  Z are known to hold
in R. It’s clear that X  Z holds too.
• We shall say that an FD set F logically implies
X  Y, and write F [X  Y
– e.g. {X  Y, Y  Z} [ X  Z
• The closure of F is the set of all FDs logically
implied by F, i.e.
F+
@ {XY | F [ XY}
• The set F+
can be big, even if F is small 
13
Closure of a set of FDs
• Which of the following are in the closure of
our Student FDs?
– addressaddress
– cidcname
– cidcname,sname
– cid,sidcname,sname
14
Candidate keys and FDs
• If R=R(A1:1, …, An:n) with FDs F and
X{A1, …, An}, then X is a candidate key
for R if
– X  A1, …,An  F+
– For no proper subset YX is
Y  A1, …,An  F+
15
Armstrong’s axioms
• Reflexivity: If YX then F  XY
– (This is called a trivial dependency)
– Example: sname,addressaddress
• Augmentation: If F  XY then F 
X,WY,W
– Example: As cidcname then
cid,sidcname,sid
• Transitivity: If F  XY and F  YZ then F 
XZ
– Example: As sid,cidcid and
cidcname, then sid,cidcname
16
Consequences of
Armstrong’s axioms
• Union: If F  XY and F  XZ then F 
XY,Z
• Pseudo-transitivity: If F  XY and F 
W,YZ then F  X,WZ
• Decomposition: If F  XY and ZY then F 
XZ
Exercise: Prove that these are consequences of
Armstrong’s axioms
17
Proof of Union Rule
Suppose that F  XY and F  XZ.
By augmentation we have
F  XX,Y
since X U X = X. Also by augmentation
F  X,YZ,Y
Therefore, by transitivity we have
F  XZ,Y
QED
18
Functional Dependencies Can be
useful in Algebraic Reasoning
Suppose R(A,B,C) is a relation schema
with dependency AB, then
)
(
, R
R B
A
π
= )
(
, R
C
A
π
A
(This is called Heath’s rule.)
19
Proof of Heath’s Rule
)
(
, R
C
A
π
A
First show that
Suppose
then
and
Since
we have )
(
, R
C
A
π
A
20
Proof of Heath’s Rule (cont.)
A
In the other direction, we must show that
Suppose Then there must exist records
and
There must also exist
Therefore, we have
so that
QED
But the functional dependency tells us that
21
Equivalence
• Two sets of FDs, F and G, are said to be
equivalent if F+
=G+
• For example:
{(A,BC), (AB)} and
{(AC), (AB)}
are equivalent
• F+
can be huge – we’d prefer to look for
small equivalent FD sets
22
Minimal cover
• An FD set, F, is said to be minimal if
1. Every FD in F is of the form XA, where A is a
single attribute
2. For no XA in F is F-{XA} equivalent to F
3. For no XA in F and ZX is
(F-{XA}){ZA} equivalent to F
1. For example, {(AC), (AB)} is a minimal
cover for {(A,BC), (AB)}
23
More on closures
• FACT: If F is an FD set, and XYF+
then
there exists an attribute AY such that
XAF+
24
Why Armstrong’s axioms?
• Soundness
– If F  XY is deduced using the rules, then
XY is true in any relation in which the
dependencies of F are true
• Completeness
– If XY is is true in any relation in which the
dependencies of F are true, then F  XY can
be deduced using the rules
25
Soundness
• Consider the Augmentation rule:
– We have XY, i.e. if t1.X=t2.X then t1.Y=t2.Y
– If in addition t1.W=t2.W then it is clear that t1.
(Y,W)=t2.(Y,W)
26
Soundness cont.
Consider the Transitivity rule:
– We have XY, i.e. if t1.X=t2.X then t1.Y=t2.Y
(*)
– We have YZ, i.e. if t1.Y=t2.Y then t1.Z=t2.Z
(**)
– Take two tuples s1 and s2 such that s1.X=s2.X
then from (*) s1.Y=s2.Y and then from (**)
s1.Z=s2.Z
27
Completeness
• Exercise
– (You may need the fact from slide 23)
28
Attribute closure
• If we want to check whether XY is in a closure of the
set F, could compute F+
and check – but expensive 
• Cheaper: We can instead compute the attribute
closure, X+
, using the following algorithm:
• Then F  XY iff Y is a subset of X+
Try this with sid,snamecname,grade
closure:= X;
repeat until no change{
if UVF, where Uclosure
then closure:=closureV
};
29
Preview of next lecture:
Goals of normalisation
• Decide whether a relation is in “good form”
• If it is not, then we will “decompose” it into a
set of relations such that
– Each relation is in “good form”
– The decomposition has not lost any information
that was present in the original relation
• The theory of this process and the notion of
“good form” is based on FDs
30
Summary
You should now understand:
• Redundancy and various forms of anomalies
• Functional dependencies
• Armstrong’s axioms
Next lecture: Schema refinement:
Normalisation

More Related Content

PPT
9 normalization
PPT
6 normalization
PDF
Cs501 fd nf
PPTX
RDBMS PARUL UNIVERSITY VADODARA BTECH CSE
PPTX
DBMS FDs and Normalization.pptx
PPT
DBMS.ppt
PPT
DBMS MODULE-5 normalisation in database management
PPT
Cross-reference or relationship relation optionAdditional01.ppt
9 normalization
6 normalization
Cs501 fd nf
RDBMS PARUL UNIVERSITY VADODARA BTECH CSE
DBMS FDs and Normalization.pptx
DBMS.ppt
DBMS MODULE-5 normalisation in database management
Cross-reference or relationship relation optionAdditional01.ppt

Similar to Functional Dependencies in rdbms with examples (20)

PPT
7. Relational Database Design in DBMS
PDF
[Www.pkbulk.blogspot.com]dbms09
PDF
Introduction to database-Normalisation
PPT
PPT
Unit05 dbms
PPT
database management systems presents.ppt
PPTX
DBMS Unit 3.pptx
PDF
6 relational schema_design
PPTX
Ch12_Normalization (1).pptxfffffffffffffffffffff
PPT
basic concepts of Entity relationship diagram
PPT
Normalization
PPTX
Fd & Normalization - Database Management System
PDF
DBMS 3.pdf
PPTX
Normalization.pptx Functional dependence
PPTX
Functional dependency
PPT
DBMS-Unit-3.0 Functional dependencies.ppt
PPTX
Relational Database Design.pptx Realtional
PPT
Normalization_dsa_project_easy_with_graph.ppt
PPT
Functional Dependencies and Normalization with well explained examples and pr...
7. Relational Database Design in DBMS
[Www.pkbulk.blogspot.com]dbms09
Introduction to database-Normalisation
Unit05 dbms
database management systems presents.ppt
DBMS Unit 3.pptx
6 relational schema_design
Ch12_Normalization (1).pptxfffffffffffffffffffff
basic concepts of Entity relationship diagram
Normalization
Fd & Normalization - Database Management System
DBMS 3.pdf
Normalization.pptx Functional dependence
Functional dependency
DBMS-Unit-3.0 Functional dependencies.ppt
Relational Database Design.pptx Realtional
Normalization_dsa_project_easy_with_graph.ppt
Functional Dependencies and Normalization with well explained examples and pr...
Ad

More from BackiyalakshmiVenkat (9)

PPTX
database models in database management systems
PPTX
Normalization in rdbms types and examples
PPTX
introduction to advanced operating systems
PPT
Introduction to Database Management Systems
PPTX
Linked list, Singly link list and its operations
PPTX
object oriented programming in PHP & Functions
PPTX
Linked Lists, Single Linked list and its operations
PPTX
Evlotion of Big Data in Big data vs traditional Business
PPTX
AN ANALYSIS OF THE REASONS FOR NON-PERFORMING ASSETS (NPAs) TO THE STATE BANK...
database models in database management systems
Normalization in rdbms types and examples
introduction to advanced operating systems
Introduction to Database Management Systems
Linked list, Singly link list and its operations
object oriented programming in PHP & Functions
Linked Lists, Single Linked list and its operations
Evlotion of Big Data in Big data vs traditional Business
AN ANALYSIS OF THE REASONS FOR NON-PERFORMING ASSETS (NPAs) TO THE STATE BANK...
Ad

Recently uploaded (20)

PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Presentation on HIE in infants and its manifestations
PDF
Classroom Observation Tools for Teachers
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
RMMM.pdf make it easy to upload and study
O7-L3 Supply Chain Operations - ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
Final Presentation General Medicine 03-08-2024.pptx
A systematic review of self-coping strategies used by university students to ...
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Presentation on HIE in infants and its manifestations
Classroom Observation Tools for Teachers

Functional Dependencies in rdbms with examples

  • 1. 1 Lecture 6: Schema refinement: Functional dependencies www.cl.cam.ac.uk/Teaching/current/Databases/
  • 2. 2 Recall: Database design lifecycle • Requirements analysis – User needs; what must database do? • Conceptual design – High-level description; often using E/R model • Logical design – Translate E/R model into relational schema • Schema refinement – Check schema for redundancies and anomalies • Physical design/tuning – Consider typical workloads, and further optimise Next two lectures
  • 3. 3 Today’s lecture • Why are some designs bad? • What’s a functional dependency? • What’s the theory of functional dependencies? • (Next lecture: How can we use this theory to classify redundancy in relation design?)
  • 4. 4 Not all designs are equally good • Why is this design bad? Data(sid,sname,address,cid,cname,grade) • Why is this one preferable? Student(sid,sname,address) Course(cid,cname) Enrolled(sid,cid,grade)
  • 5. 5 An instance of our bad design sid sname addres s ci d cname grade 124 Britney USA 206 Database A++ 204 Victoria Essex 202 Semantics C 124 Britney USA 201 S/Eng I A+ 206 Emma London 206 Database B- 124 Britney USA 202 Semantics B+
  • 6. 6 Evils of redundancy • Redundancy is the root of many problems associated with relational schemas – Redundant storage – Update anomalies – Insertion anomalies – Deletion anomalies – LOW TRANSACTION THROUGHPUT • In general, with higher redundancy, if transactions are correct (no anomalies), then they have to lock more objects thus causing greater contention and lower throughput • (Aside: Could having a dummy value, NULL, help?)
  • 7. 7 Decomposition • We remove anomalies by replacing the schema Data(sid,sname,address,cid,cname,grade) with Student(sid,sname,address) Course(cid,cname) Enrolled(sid,cid,grade) • Note the implicit extra cost here • Two immediate questions: 1. Do we need to decompose a relation? 2. What problems might result from a decomposition?
  • 8. 8 Functional dependencies • Recall: – A key is a set of fields where if a pair of tuples agree on a key, they agree everywhere • In our bad design, if two tuples agree on sid, then they also agree on address, even though the rest of the tuples may not agree
  • 9. 9 Functional dependencies cont. • We can say that sid determines address – We’ll write this sid  address • This is called a functional dependency (FD) • (Note: An FD is just another integrity constraint)
  • 10. 10 Functional dependencies cont. • We’d expect the following functional dependencies to hold in our Student database – sid  sname,address – cid  cname – sid,cid  grade • A functional dependency X  Y is simply a pair of sets (of field names) – Note: the sloppy notation A,B  C,D rather than {A,B}  {C,D}
  • 11. 11 Formalities • Given a relation R=R(A1:1, …, An:n), and X, Y ({A1, …, An}), an instance r of R satisfies XY, if – For any two tuples t1, t2 in R, if t1.X=t2.X then t1.Y=t2.Y • Note: This is a semantic assertion. We can not look at an instance to determine which FDs hold (although we can tell if the instance does not satisfy an FD!)
  • 12. 12 Properties of FDs • Assume that X  Y and Y  Z are known to hold in R. It’s clear that X  Z holds too. • We shall say that an FD set F logically implies X  Y, and write F [X  Y – e.g. {X  Y, Y  Z} [ X  Z • The closure of F is the set of all FDs logically implied by F, i.e. F+ @ {XY | F [ XY} • The set F+ can be big, even if F is small 
  • 13. 13 Closure of a set of FDs • Which of the following are in the closure of our Student FDs? – addressaddress – cidcname – cidcname,sname – cid,sidcname,sname
  • 14. 14 Candidate keys and FDs • If R=R(A1:1, …, An:n) with FDs F and X{A1, …, An}, then X is a candidate key for R if – X  A1, …,An  F+ – For no proper subset YX is Y  A1, …,An  F+
  • 15. 15 Armstrong’s axioms • Reflexivity: If YX then F XY – (This is called a trivial dependency) – Example: sname,addressaddress • Augmentation: If F XY then F X,WY,W – Example: As cidcname then cid,sidcname,sid • Transitivity: If F XY and F YZ then F XZ – Example: As sid,cidcid and cidcname, then sid,cidcname
  • 16. 16 Consequences of Armstrong’s axioms • Union: If F XY and F XZ then F XY,Z • Pseudo-transitivity: If F XY and F W,YZ then F X,WZ • Decomposition: If F XY and ZY then F XZ Exercise: Prove that these are consequences of Armstrong’s axioms
  • 17. 17 Proof of Union Rule Suppose that F XY and F XZ. By augmentation we have F XX,Y since X U X = X. Also by augmentation F X,YZ,Y Therefore, by transitivity we have F XZ,Y QED
  • 18. 18 Functional Dependencies Can be useful in Algebraic Reasoning Suppose R(A,B,C) is a relation schema with dependency AB, then ) ( , R R B A π = ) ( , R C A π A (This is called Heath’s rule.)
  • 19. 19 Proof of Heath’s Rule ) ( , R C A π A First show that Suppose then and Since we have ) ( , R C A π A
  • 20. 20 Proof of Heath’s Rule (cont.) A In the other direction, we must show that Suppose Then there must exist records and There must also exist Therefore, we have so that QED But the functional dependency tells us that
  • 21. 21 Equivalence • Two sets of FDs, F and G, are said to be equivalent if F+ =G+ • For example: {(A,BC), (AB)} and {(AC), (AB)} are equivalent • F+ can be huge – we’d prefer to look for small equivalent FD sets
  • 22. 22 Minimal cover • An FD set, F, is said to be minimal if 1. Every FD in F is of the form XA, where A is a single attribute 2. For no XA in F is F-{XA} equivalent to F 3. For no XA in F and ZX is (F-{XA}){ZA} equivalent to F 1. For example, {(AC), (AB)} is a minimal cover for {(A,BC), (AB)}
  • 23. 23 More on closures • FACT: If F is an FD set, and XYF+ then there exists an attribute AY such that XAF+
  • 24. 24 Why Armstrong’s axioms? • Soundness – If F XY is deduced using the rules, then XY is true in any relation in which the dependencies of F are true • Completeness – If XY is is true in any relation in which the dependencies of F are true, then F XY can be deduced using the rules
  • 25. 25 Soundness • Consider the Augmentation rule: – We have XY, i.e. if t1.X=t2.X then t1.Y=t2.Y – If in addition t1.W=t2.W then it is clear that t1. (Y,W)=t2.(Y,W)
  • 26. 26 Soundness cont. Consider the Transitivity rule: – We have XY, i.e. if t1.X=t2.X then t1.Y=t2.Y (*) – We have YZ, i.e. if t1.Y=t2.Y then t1.Z=t2.Z (**) – Take two tuples s1 and s2 such that s1.X=s2.X then from (*) s1.Y=s2.Y and then from (**) s1.Z=s2.Z
  • 27. 27 Completeness • Exercise – (You may need the fact from slide 23)
  • 28. 28 Attribute closure • If we want to check whether XY is in a closure of the set F, could compute F+ and check – but expensive  • Cheaper: We can instead compute the attribute closure, X+ , using the following algorithm: • Then F XY iff Y is a subset of X+ Try this with sid,snamecname,grade closure:= X; repeat until no change{ if UVF, where Uclosure then closure:=closureV };
  • 29. 29 Preview of next lecture: Goals of normalisation • Decide whether a relation is in “good form” • If it is not, then we will “decompose” it into a set of relations such that – Each relation is in “good form” – The decomposition has not lost any information that was present in the original relation • The theory of this process and the notion of “good form” is based on FDs
  • 30. 30 Summary You should now understand: • Redundancy and various forms of anomalies • Functional dependencies • Armstrong’s axioms Next lecture: Schema refinement: Normalisation