Professional Documents
Culture Documents
1
• Functional Dependency (FD) is a constraint that determines
the relation of one attribute to another attribute in a
Database Management System (DBMS).
2
• A functional dependency is denoted by an arrow "→".
3
• SID → SNAME
SID SNAME SID SNAME
1 SAI 1 SAI
2 SAI 1 SAI
SID SNAME
SID SNAME
1 SAI
1 SAI
1 VARUN
2 VARUN
4
Rules of Functional Dependencies
• Reflexive rule –. If X is a set of attributes and Y is subset of X,
then X holds a value of Y.
5
• Types of Functional Dependencies in DBMS
• There are mainly four types of Functional Dependency in
DBMS. Following are the types of Functional Dependencies in
DBMS:
• Multivalued Dependency
• Trivial Functional Dependency
• Non-Trivial Functional Dependency
• Transitive Dependency
6
• Multivalued Dependency in DBMS
• Multivalued dependency occurs in the situation where there
are multiple independent multivalued attributes in a single
table.
• A multivalued dependency is a complete constraint between
two sets of attributes in a relation. It requires that certain
tuples be present in a relation.
Example
Example
Sid Sname
Example:
Dept HoD
• (Dept} -> {HoD} (if we know the Dept, we knows the HoD name)
• But HoD is not a subset of Dept, and hence it's non-trivial functional
dependency.
9
• Transitive Dependency in DBMS
• A Transitive Dependency is a type of functional dependency which
happens when t is indirectly formed by two functional
dependencies.
• Example
10
Inference Rule (IR):
• The Armstrong's axioms are the basic inference rule.
• The inference rule is a type of assertion. It can apply to a set of
FD(functional dependency) to derive other FD.
• Using the inference rule, we can derive additional functional dependency
from the initial set.
11
Reflexive Rule (IR1)
• In the reflexive rule, if Y is a subset of X, then X determines Y.
• If X ⊇ Y then X → Y
• Example:
For R(ABC), if AB → B then A → B
12
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.
If X → Y then XZ → YZ
• Example:
For R(ABC), if A → B then AC → BC
13
Transitive Rule (IR3)
• If X → Y and Y → Z then X → Z
• Example:
For R(ABC), if A → B, B → C then A → C
14
Union Rule (IR4)
• Union rule says, if X determines Y and X determines Z, then X must also
determine Y and Z.
• If X → Y and X → Z then X → YZ
• Example:
For R(ABC), if A → B, A → C then A → BC
• 1. A → B(given)
2. A → C(given)
3. A → AB (using IR2 on 1 by augmentation with A)
4. AB → BC (using IR2 on 2 by augmentation with Y)
5. A → BC (using IR3 on 3 and 4)
15
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.
• If X → YZ then X → Y and X → Z
• Example:
For R(ABC), if A → BC then A → B, A → C
• Proof:
• 1. A → BC (given)
2. BC → B (using IR1 Rule)
3. A → B (using IR3 on 1 and 2)
• 1. A → BC (given)
2. BC → C (using IR1 Rule)
16
3. A → C (using IR3 on 1 and 2)
Pseudo transitive Rule (IR6)
• In Pseudo transitive Rule, if X determines Y and YZ determines
W, then XZ determines W.
• If X → Y and YZ → W then XZ → W
• Example:
For R(ABCD), if A → B, BD → C then AD → C
• Proof:
• 1. A → B (given)
2. BD → C (given)
3. AD→ BD (using IR2 on 1 by augmenting with W)
4. AD → C (using IR3 on 3 and 2)
17
• Example: R(A, B, C, D)
• FD={A→B; B→C; C→D}
• Find candidate key?
• CK={} + A B+ C+ D+ AB+
A+ = {} B+ = {} C+ = D+ = {}
={A} ={B} {} ={D}
={A B} // ={B
A→B C}//B→C ={C}
={ A B C}// ={B C D} ={C
//C→ D
B→C D}
={A B C D}//
C→D
• CK={A }
• AB+ , AC+, AD+ , BC+ ,BD+, CD+ , ABC+, ABD+ , ACD+ ,BCD+ , ABCD+
A+ , AB+ , AC+, AD+ , ABC+, ABD+ , ACD+, ABCD+ -- Following attributes can visit all
attributes //All these are part of keys
18
• Example: R(A, B, C, D)
• FD={A→B; B→C; C→D}
• Find candidate key?
• CK={}
19
• Example: R(A, B, C, D)
• FD={A→B; B→C; C→D;D-> A}
• Find candidate key?
20
• Example: R(A, B, C, D,E)
• FD={A→B; BC→D; E→C;D-> A}
• Find candidate key?
21
• Given the following relation instance.
-------
X Y Z
-------
1 4 2
1 5 3
1 6 3
3 2 2
-------
• Which of the following functional dependencies are satisfied by the
instance?
(a) XY -> Z and Z -> Y
(b) YZ -> X and Y -> Z
(c) YZ -> X and X -> Z
(d) XZ -> Y and Y -> X
• Given the following relation instance.
-------
X Y Z
-------
1 4 2
1 5 3
1 6 3
3 2 2
-------
• Which of the following functional dependencies are satisfied by the
instance?
(a) XY -> Z and Z -> Y
(b) YZ -> X and Y -> Z
(c) YZ -> X and X -> Z
(d) XZ -> Y and Y -> X
• Consider the relation scheme R=(E,F,G,H,I,J,K,L,M,N) and the
set of functional dependencies
{{E,F}→{G},{F}→{I,J},{E,H}→{K,L},{K}→{M},{L}→{N}}
on R. What is the key for R?
(a) {E,F}
(b) {E,F,H}
(c) {E,F,H,K,L}
(d) {E}
• Consider the relation scheme R=(E,F,G,H,I,J,K,L,M,N) and the
set of functional dependencies
{{E,F}→{G},{F}→{I,J},{E,H}→{K,L},{K}→{M},{L}→{N}}
on R. What is the key for R?
(a) {E,F}
(b) {E,F,H}
(c) {E,F,H,K,L}
(d) {E}
• Consider a relation scheme R = (A, B, C, D, E, H) on which the
following functional dependencies hold: {A–>B, BC–>D, E–>C,
D–>A}. What are the candidate keys of R?
(a) AE, BE
(b) AE, BE, DE
(c) AEH, BEH, BCH
(d) AEH, BEH, DEH
• Consider a relation scheme R = (A, B, C, D, E, H) on which the
following functional dependencies hold: {A–>B, BC–>D, E–>C,
D–>A}. What are the candidate keys of R?
(a) AE, BE
(b) AE, BE, DE
(c) AEH, BEH, BCH
(d) AEH, BEH, DEH
Update marks=80 student
where sid=1 and cname=c1;
Normalization
• Normalization divides the larger table into the smaller table and links them
using relationship.
• The normal form is used to reduce redundancy from the database table.
28
Other advantages of normalization
• This technique makes it possible to make your databases more logical
and natural, reducing their size and simplifying the structure to make
product data easier to locate, contrast and retrieve.
• Increased security
29
When not to use normalization:
• Whether organization don’t have the right resources (since it’s a demanding
process that will need full time dedication for a while).
• If organization work with very complex designs which don’t fit well with a
standard normalization process.
30
Objectives of database normalization
• To correct duplicate data and database anomalies.
• To reduce the delay and complexity of checking databases when new types of
data need to be introduced.
31
Database Normal Forms
• List of Normal Forms
– 1NF (First Normal Form)
– 2NF (Second Normal Form)
– 3NF (Third Normal Form)
– BCNF (Boyce-Codd Normal Form)
– 4NF (Fourth Normal Form)
– 5NF (Fifth Normal Form)
32
First Normal Form (1NF )
• If a relation contain composite or multi-valued attribute, it violates first
normal form.
• Rules:
– Each table cell should contain a single value.
– Each record needs to be unique.
33
Employee Table:
34
Employee Table:
EMP_ID EMP_NAME EMP_PHONE
ID Name Courses
16014451 Ramakanth C1, C2
16014452 Sneha C3
16014453 Sowmya C2, c3
ID Name Courses
16014451 Ramakanth C1
16014451 Ramakanth C2
16014452 Sneha C3
16014453 Sowmya C2
16014453 Sowmya C3
36
Second Normal Form (2NF )
• For a table to be in the Second Normal Form, it must satisfy two
conditions:
– The table should be in the First Normal Form.
– There should be no Partial Dependency.
• (OR) all non-key attributes are fully functional dependent on the primary key
37
What is Dependency?
• Student
38
What is Partial Dependency?
• For a simple table like Student.
– student_id
– name
– branch
– address
39
What is Partial Dependency?
• Let's assume another table for Subject.
– subject_id
– subject_name
40
student_id subject_id marks teacher
41
Student_id, subject_id → marks
Student_id, subject_id → teacher
subject_id → teacher
subject_id subject_name
1 Java
2 C++
3 Php
42
• How to remove Partial Dependency?
43
• R(A,B,C,D,E,F)
• FD:{A—>B, B-> C, C->D, D->E}
• Check whether given table is in 2nd NF?
Ans: ={AFBCDE}
CK={AF}
Prime attributes = {A, F}
Non-prime attributes = {B, C, D, E}
44
• R(A,B,C,D)
• FD:{A—>B, B-> C}
AD-> B; AD->C
45
• R(A,B,C,D)
• FD:{A—>B, C-> D}
• AC+ = {ACBD}
• CK={AC}
• FD{AC->B,AC->D}
46
3NF(Third normal forms)
47
SID SNAME S_City S_State Age
CK={SID}
Prime attributes={SID}
48
Non-Prime attributes={SNAME,S_City,S_state,Age}
• R(A,B,C,D)
• FD:{A—>B, B-> C,C->D}
• CK={A}
• Prime Attribute{A}
• Non-prime attributes={B,C,D}
FD’s Verification Valid?
A—>B X –> Y Yes
• X is a super key.
• Y is a prime attribute
B-> C X –> Y • Not valid, there is TD
• X is a super key.
• Y is a prime attribute
C->D X –> Y • Not valid, there is TD
• X is a super key.
• Y is a prime attribute 49
• R(A,B,C,D)
• FD:{A—>B, B-> C,C->D}
• CK={A}
FD’s Verification Valid?
50
• R(A,B,C,D) FD’s Verification Valid? Tables
• FD:{A—>B, B-> C,C->D} FD11: X –> Y CK={C} Yes R11 =
C->D • X is a super key. {C,D}
• CK={A} • Y is a prime attribute
FD’s Verification Valid? FD12 : X –> Y CK={B} Yes R12 =
• X is a super key. {B,C}
X –> Y CK={B} Yes B->C • Y is a prime attribute
FD1:
B-> CD • X is a super key.
FD2 : X –> Y CK={C} Yes R2 =
• Y is a prime attribute
• X is a super key. {C,D}
X –> Y CK={B} Not C->D • Y is a prime attribute
FD1 :
• X is a super key. satisfyi
C->D • Y is a prime attribute ng FD3 : X –> Y CK={A} Yes R3 =
• X is a super key. {A,B}
A->B • Y is a prime attribute
51
• R(A,B,C,D) FD’s Verification Valid? Tables
• FD:{A—>B, B-> C,C->D} FD11: X –> Y CK={C} Yes R11 =
C->D • X is a super key. {C,D}
• CK={A} • Y is a prime attribute
FD12 : X –> Y CK={B} Yes R12 =
• X is a super key. {B,C}
B->C • Y is a prime attribute
• R12 = {B,C} FD12 :B->C FD2 : X –> Y CK={C} Yes R2 =
• X is a super key. {C,D}
• R2 = {C,D} FD2 : C->D C->D • Y is a prime attribute
• R3 = {A,B} FD3 : A->B FD3 : X –> Y CK={A} Yes R3 =
• X is a super key. {A,B}
A->B • Y is a prime attribute
52
• Boyce-Codd Normal Form (BCNF)
• Boyce-Codd Normal Form or BCNF is an extension to the third normal
form, and is also known as 3.5 Normal Form.
53
• Ex-1: R (A,B,C)
• FD:{A-> B; B->C;C->A}
• CK={A, C, B}
FD Rules Valid?
A-> B Any dependency A → B Yes
(CK={A, C, B})
A should be a super key.
B->C Any dependency A → B Yes
(CK={A, C, B})
A should be a super key.
C->A Any dependency A → B Yes
(CK={A, C, B})
54
A should be a super key.
• Ex-2: R=(A,B,C,D,E) ; FD={A->BCDE; BC->ACE; D->E} What is the highest NF?
• A+ ={ABCDE}
1NF 2NF 3NF BCNF
• +
BC ={BCACED}
N
• CK={A,BC}
• Prime attributes={A, B, C}
56
• Ex-2: R=(A,B,C,D,E) ; FD={A->BCDE; BC->ACE; D->E} What is the highest NF?
• A+ ={ABCDE}
1NF 2NF 3NF BCNF
• +
BC ={BCACED}
Y N N
• CK={A,BC}
• Prime attributes={A, B, C}
57
• Ex-3: How to decompose into BCNF?
• FD{AB->C, A->DE, B->F, F->GH, D->IJ}, R(A,B,C,D,E,F,G,H,I)
• AB+ ={ABCDEFGHIJ}
• A+ ={ADEIJ} D+ ={DIJ} B+ ={BFGH} F+ ={FGH}
ABCDEFGHIJ
R1 {ABC} R2 {DEFCGHIJ}
58
• Ex-3: How to decompose into BCNF?
• FD{AB->C, A->DE, B->F, F->GH, D->IJ}, R(A,B,C,D,E,F,G,H,I)
• AB+ ={ABCDEFGHIJ}
• A+ ={ADEIJ} D+ ={DIJ} B+ ={BFGH} F+ ={FGH}
ABCDEFGHIJ
R1 {ABC} R2 {DEFCGHIJ}
FD1:{AB->C}
R21 {ADEIJ} R22{BFGH}
59
• Ex-3: How to decompose into BCNF?
• FD{AB->C, A->DE, B->F, F->GH, D->IJ}, R(A,B,C,D,E,F,G,H,I)
ABCDEFGHIJ
R1 {ABC} R2 {DEFCGHIJ}
FD1:{AB->C}
R21 {ADEIJ} R22{BFGH}
2NF
3 NF
BCNF
61