Upload
aidan-frost
View
213
Download
1
Embed Size (px)
Citation preview
Functional dependencies
1
Functional dependencies
Functional dependencies
2
Outline
motivation: update anomalies cause: not expressed constraints on data (FDs) functional dependencies (FDs)
• definitions• examples• concepts and terminology• (more) advanced theoretical issues (in brief)
Functional dependencies
3
Redundancy
Student-Modules
S_id S_name P_ tutor Module Val Res
50021 G. Zolla MFU Database Systems 1cu A
50021 G. Zolla MFU Software Engineering 1cu null
50021 G. Zolla MFU Advanced Programming 1/2cu B
50012 D. Petrescu MFU Computing 1cu null
50012 D. Petrescu MFU Mathematics 1/2cu A
41002 T.A. Flo MFU HCI 1/2cu null
50033 D. Wise MH Database Systems 1cu null
50033 D. Wise MH Algorithms 1cu null
Functional dependencies
4
Update anomalies - insertion
insert the fact that 50012 takes “Networks - Introduction”; the name of the student and the name of the personal tutor have to be entered as well; this is prone to errors inconsistent data
S_id S_name P_ tutor Module Val Res
50021 G. Zolla MFU Database Systems 1cu A
50012 D. Petrescu MFU Computing 1cu null
50012 D. Petrescu MFU Mathematics 1/2cu A
50012 D. Pwtrwscu MFFU Networks 1/2cu null
50033 D. Wise MH Algorithms 1cu null
can you identify other kinds of update anomalies on this relation?
Functional dependencies
5
Update anomalies - deletion
delete the fact that 41002 takes “HCI”, in the original table; relevant information will be also deleted - about “T.A Flo” and about “HCI”.
S_id S_name P_ tutor Module Val Res
50021 G. Zolla MFU Database Systems 1cu A
50021 G. Zolla MFU Software Engineering 1cu null
50021 G. Zolla MFU Advanced Programming 1/2cu B
50012 D. Petrescu MFU Computing 1cu null
50012 D. Petrescu MFU Mathematics 1/2cu A
50033 D. Wise MH Database Systems 1cu null
50033 D. Wise MH Algorithms 1cu null
Functional dependencies
6
Update anomalies - modification
it is possible to modify an attribute and to bring the relation in an inconsistent state; e.g. it is possible (e.g. by mistake) to modify the value of “Database Systems” to “1/2cu” in just some rows; such situations must be avoided
S_id S_name P_ tutor Module Val Res
50021 G. Zolla MFU Database Systems 1/2cu A
50021 G. Zolla MFU Software Engineering 1cu null
41002 T.A. Flo MFU HCI 1/2cu null
50033 D. Wise MH Database Systems 1cu null
50033 D. Wise MH Algorithms 1cu null
Functional dependencies
7
Cause
… of anomalies• redundancy
… of redundancy• constraints on data that are not considered or expressed
in the relational model (or, more specifically, on for a particular relation)
• (some of) these constraints are called Functional Dependencies (FDs)
– (others: multiple dependencies, …)
Functional dependencies
8
To eliminate the problem
express the existing functional dependencies• this is done by choosing particular forms for relations -
normal forms• a relation is in a certain normal form if if it does not
contain certain kinds of functional dependencies• a relation in a certain normal form eliminates certain
kinds of update anomalies• a relation that is not in a certain normal form can be
transformed (decomposed) into an equivalent set of relations - this process is called normalisation
Functional dependencies
9
Functional dependency (FD)
R - relation, X and Y - subset of attributes of RX Y iffin every possible legal value of R each X-value has a single Y-value associated
time independent (for all time)
Functional dependencies
10
Examples
S_id S_nameS_id P_TutorS_id S_id(S_id, P_tutor) P_tutor(S_id, S_name, P_tutor) P_tutorModule Val(S_id, Module) Res(S_id, S_name, P_tutor, Module, Val) Res
Functional dependencies
11
Concepts
FD is a semantic concept determinant / dependent trivial / non-trivial FD left-irreducible
• yes: (S_id, P_tutor) P_tutor• no: (S_id, Module) Res
closure irreducible set
Functional dependencies
12
Functional diagram
S_id
City
P_tutor
S_name
S_id
ModuleRes
Module
Functional dependencies
13
Closure
all FDs that can be derived from a given set S• notation S+
Armstrong’s inference rules• if B A then A B• if A B then AC BC• if A B and B C then A C• sound and complete
– other rules can be inferred (make the derivation process easier)
– A BC iff A B and A C
– A B and C D then AC BD
Functional dependencies
14
Irreducible set
S1 covers S2 iff S2+ S1
+
S is irreducible iff• RHS of every FD is non-composite• all FDs in S are left-irreducible• no FD ca be discarded from S without changing S+
a database that enforces S enforces, in fact, S+
the irreducible set of S is S’ iff• S’ - irreducible• S’+ = S+
more efficient to work with the irreducible set
Functional dependencies
15
Conclusion
2NF, 3NF and BCNF will be defined based on FDs