CSMI14: Database Management Systems: Dr. R. Bala Krishnan Asst. Prof. Dept. of CSE NIT, Trichy - 620 015
CSMI14: Database Management Systems: Dr. R. Bala Krishnan Asst. Prof. Dept. of CSE NIT, Trichy - 620 015
CSMI14: Database Management Systems: Dr. R. Bala Krishnan Asst. Prof. Dept. of CSE NIT, Trichy - 620 015
Systems
Dr. R. Bala Krishnan
Asst. Prof.
Dept. of CSE
NIT, Trichy – 620 015
Ph: 999 470 4853 E-mail: [email protected]
Course Content
2
Course Content
3
Books
• Text Books (TB)
Silberschatz, Henry F. Korth, S. Sudharshan, “Database System
Concepts”, Fifth Edition, Tata McGraw Hill, 2006.
J. Date, A. Kannan, S. Swamynathan, “An Introduction to Database
Systems”, Eighth Edition, Pearson Education, 2006.
4
Books & Chapters
Unit Book Chapter
1 TB1 1
1_ TB1 6
2 RB2 3, 4
2_ TB1 3
3 RB2 19
5 TB1 11, 12
• https://www.databasestar.com/sql-practice/
• http://sqlfiddle.com/#!9/7379d5/1 5
Evaluation Method
Sl. No. Mode of Assessment Week / Date Duration % Weightage
1. Cycle Test 1 As per Academic 1 hour 20
Schedule
2. Cycle Test 2 As per Academic 1 hour 20
Schedule
3. Programming Sep 4th Week - 15
Assignment 1 / PPT
Presentation
4. Programming Nov 1st Week - 15
Assignment 2 / PPT
Presentation
CPA Compensation As per Academic
Assessment Schedule
5. Final Assessment As per Academic 2 hour 30
Schedule
6
Unit III
7
Functional Dependency
• Basically a many-to-one relationship from one set of attributes to
another within a given relation variable
• X → Y; XY → Z, where X & XY are called Determinant Attributes and Y
& Z are called Dependent Attributes
• Whenever two tuples of a relation agree on their “X” value they will also
agree on their “Y” value
• Eg: Branch No. / Serial No. = {S1, S2, S3, S4}; City = {London, Paris};
Product No. = {P1, P2, P4, P5}; Quantity = {100, 200, 400}
SCP Possible Functional Dependencies:
Serial No. City Product No. Quantity Serial No. → City
S1 London P1 100 Serial No. → Quantity
Quantity → Serial No.
S1 London P2 100
{Serial No., Product No.} → Quantity
S2 Paris P1 200 {Serial No., Product No.} → City
S2 Paris P2 200 {Serial No., Product No.} → {City, Quantity}
S3 Paris P2 200 And so on . . .
S4 London P2 400
S4 London P4 400
S4 London P5 400 8
Functional Dependency
SCP Possible Functional Dependencies:
Serial No. City Product No. Quantity Serial No. → City
Serial No. → Quantity
S1 London P1 100 Quantity → Serial No.
S1 London P2 100 {Serial No., Product No.} → Quantity
S2 Paris P1 200 {Serial No., Product No.} → City
{Serial No., Product No.} → {City, Quantity}
S2 Paris P2 200 And so on . . .
S3 Paris P2 200
Lossy / Lossless Decomposition
S4 London P2 400
S4 London P4 400 Serial No. Product No. Quantity
S4 London P5 400 S1 P1 100
S1 P2 100
Serial No. City Serial No. Quantity S2 P1 200
S1 London S1 100 S2 P2 200
S2 Paris S2 200 S3 P2 200
S3 Paris S3 200 S4 P2 400
S4 London S4 400 S4 P4 400
9
S4 P5 400
Armstrong’s Axioms
• If F is a set of functional dependencies then the closure of F, denoted
as F+, is the set of all functional dependencies logically implied by F
• Armstrong’s Axioms are a set of rules, that when applied repeatedly,
generates a closure of functional dependencies
10
Armstrong’s Axioms
• Secondary Rules -> Can be derived from the above axioms
11
Armstrong’s Axioms
• Armstrong axioms refer to the Sound and Complete
ABCDE = {A, B, C, D, E, AB, AC, AD, AE, BC, BD, BE, CD, CE, DE, ABC, ABD, ABE,
ACD, ACE, ADE, BCD, . . .} 13
Closure of a Set
Columns in Table: A,B, C, D, E
• Functional Dependency: A → BC; CD → E; B → D; E → A
14
Closure of a Set
A+ = ABC CD+ = CDE B+ = BD E+ = EA
ABCD CDEA (Not a Super Key. So,
try applying Axioms)
EABC
ABCDE CDEAB BC → DC EABCD
BC+ = BCD
BCDE
BCDEA
• A+, CD+, BC+ and E+ => All are super keys Along with identified super keys, any
combination of keys containing A or
• How to find minimal super key?
CD or BC or E are also super keys
- A+ and E+ are already minimal super keys
- Check whether CD+ and BC+ are minimal super keys or not
CD+ => C+, D+ => C+ and D+ are not super keys => CD+ is not a super key
CD+ is a minimal super key
BC+ => B+, C+ => B+ and C+ are not super keys => BC+ is not a super key
CD+ is a minimal super key 15
Equivalence of Functional Dependency
• A set of Functional Dependency (FD) “F” is said to cover another set of FD
and F covers E
16
Equivalence of Functional Dependency
• Let, F = {A → B, B → C, AC → D}
G = {A → B, B → C, A → D}
• Solution: We can conclude that F and G are equivalent, if we prove that
all FD’s in F can be inferred from the set of FD’s in G and vice versa
• Find the closure for the LHS elements of F, using the FD of G
• Find the closure for the LHS elements of G, using the FD of F
F = {A → B, B → C, AC → D} G = {A → B, B → C, A → D}
A+ = AB B+ = BC A+ = ABD B+ = BC AC+ = AC
ABC ABDC
ABCD
Using F Using G
A+ = ABC B+ = B A+ = AB A+ (Already
ABC Calculated)
Not Equivalent
18
Canonical Cover
{ABCDE}; Functional Dependency: {A → BC; CD → E; B → D; E → A}
{A → BC; CD → E; B → D; E → A}
• A canonical cover is a simplified and reduced version of the given set of
functional dependencies
• Since it is a reduced version, it is also called as Irreducible Set
• Characteristics
- Canonical cover is free from all the extraneous functional
dependencies
- Closure of canonical cover is same as that of the given set of functional
dependencies
- Canonical cover is not unique and may be more than one for a given
set of functional dependencies
• Need
- Working with the set containing extraneous functional dependencies
increases the computation time
- Given set is reduced by eliminating the useless functional
dependencies
- Reduces the computation time and working with the irreducible set
becomes easier 19
Steps to Find Canonical Cover
• Step 1
- Write the given set of functional dependencies in such a way that
each functional dependency contains exactly one attribute on its
right side
- Eg: The functional dependency X → YZ will be written as - X → Y; X
→Z
{A → BC; CD → E; B → D; E → A} => {A → B; A → C; CD → E; B → D; E → A}
• Step 2
- Consider each functional dependency one by one from the set
obtained in Step 1
- Determine whether it is essential or non-essential
- To determine whether a functional dependency is essential or not,
compute the closure of its left side
Once by considering that the particular functional
dependency is present in the set
Once by considering that the particular functional
dependency is not present in the set
20
Steps to Find Canonical Cover
Case 1: Results Come Out to be Same-
If results come out to be same, it means that
the presence or absence of that functional
dependency does not create any difference ->
Non-essential
Eliminate that functional dependency from
the set
Case 2: Results Come Out to be Different-
If results come out to be different, it means
that the presence or absence of that
functional dependency creates a difference ->
Essential
Do not eliminate that functional dependency
from the set
Mark that functional dependency as essential
{A → B; A → C; CD → E; B → D; E → A} => {A → B; A → C; CD → E; B → D}
21
Steps to Find Canonical Cover
• Step 3
- Consider the newly obtained set of functional dependencies after performing
Step 2
- Check if there is any functional dependency that contains more than one
attribute on its left side
Case 1: No-
There exists no functional dependency containing more than
one attribute on its left side -> Set obtained in Step 2 is the
canonical cover
Case 2: Yes-
There exists at least one functional dependency containing
more than one attribute on its left side
Consider all such functional dependencies one by one
Check if their left side can be reduced
Use the following steps to perform a check-
Consider a functional dependency
Compute the closure of all the
{A → B; A → C; CD → E; B → D} possible subsets of the left side of
that functional dependency
{CD} => {C}, {D} If any of the subsets produce the
+
CD = { } same closure result as produced by
C+ = { } the entire left side, then replace the
D+ = { } left side with that subset
After this step is complete, the set
obtained is the canonical cover
22
https://www.gatevidyalay.com/tag/irreducible-set-of-functional-dependencies-in-dbms/
Normal Forms
• Normalization is the process of minimizing redundancy from a relation or
set of relations
anomalies
tables
https://www.geeksforgeeks.org/normal-forms-in-dbms/ 23
Normal Forms
25
2NF
• Note that, there are many courses having the same course fee
- COURSE_FEE cannot alone decide the value of COURSE_NO or STUD_NO
- COURSE_FEE together with STUD_NO cannot decide the value of
COURSE_NO
- COURSE_FEE together with COURSE_NO cannot decide the value of
STUD_NO
• COURSE_FEE would be a non-prime attribute, as it does not belong to the only
one candidate key {STUD_NO, COURSE_NO}
• But, COURSE_NO -> COURSE_FEE, i.e., COURSE_FEE is dependent only on
COURSE_NO, which is a proper subset of the candidate key {STUD_NO,
COURSE_NO}
• Non-prime attribute COURSE_FEE is dependent on a proper subset of the
candidate key, which is a partial dependency
26
• So, this relation is not in 2NF
2NF
• To be in second normal form, a relation must be in first normal form and
relation must not contain any partial dependency
- Partial Dependency: If the proper subset of candidate key
determines non-prime attribute, it is called partial dependency
Non-Prime Attribute -> Attribute does not belong to any
candidate key
• A relation is in 2NF if it has No Partial Dependency, i.e., no non-prime
attribute (attributes which are not part of any candidate key) is
dependent on any proper subset of any candidate key of the table
• Non-Prime Attribute -> Attribute does not belong to any candidate key
• Non-prime attribute must be fully dependent on candidate key. If not, then it violates 2NF
27
2NF
• To convert the above relation to 2NF, we need to split the table into two
tables such as
- Table 1: STUD_NO, COURSE_NO
- Table 2: COURSE_NO, COURSE_FEE
• Note: 2NF tries to reduce the redundant data getting stored in memory
- For instance, if there are 100 students taking C1 course, we don’t
need to store its Fee as 1000 for all the 100 records, instead, once
we can store it in the second table as the course fee for C1 is 1000
28
3NF
A relation R is not in 3NF, when there is some attribute which depends on some
non-prime attribute
29
3NF
33
Discussion
• For a relation, with only one candidate key, 3NF and BCNF are equivalent
{VW → X; YZ → X; W → Y}
decomposition
https://www.geeksforgeeks.org/boyce-codd-normal-form-bcnf/
34
Dependency Preserving
• A Decomposition D = { R1, R2, R3, …., Rn } of R is dependency preserving
wrt a set F of Functional dependency if: (F1 ∪ F2 ∪ … ∪ Fm)+ = F+
https://www.geeksforgeeks.org/data-base-dependency-preserving-decomposition/
35
Example for Dependency Preserving
Decomposition
https://www.geeksforgeeks.org/data-base-dependency-preserving-decomposition/
36
4NF
• 4NF deals with Multi-values dependencies
A →→ B
- 4NF tries to handle the problem created by 1NF
37
4NF
Department Job Part
d1 {J1, J2} {P1, P2}
d2 {J1, J2} {P1, P2}
Department Job
Department Job Part d1 J1
d1 J1 P1 d1 J2
d1 J1 P2 d2 J1
d1 J2 P1 d2 J2
=>
d1 J2 P2 +
d2 J1 P1
Department Part
d2 J1 P2
d1 P1
d2 J2 P1
d1 P2
d2 J2 P2
d2 P1
d2 P2
38
5NF
• Any relation in order to be in the fifth normal form must satisfy the
following conditions:
- Must be in Fourth Normal Form (4NF)
- Should have no join dependency and also the joining must be
lossless
A Join dependency is generalization of Multi-valued
dependency
A JD {R1, R2, ..., Rn} is said to hold over a relation R if R1, R2,
R3, ..., Rn is a lossless-join decomposition of R
• In the fifth normal form the relation must be decomposed in as many
sub-relations as possible so as to avoid any kind of redundancy and there
must be no extra tuples generated when the sub-relations are combined
together by using natural join
• A relation in 5NF cannot be decomposed further without any kind of
modification in the meaning or facts
• 5NF is also known as Project Join Normal Form (PJNF)
39
5NF
+ +
40
5NF
+ +
↓ Original
Lossless Decomposition:
• All the tuples of original relation are successfully recreated through join operation
• No extra tuples are formed during join operation 41
4NF vs 5NF
42
6NF
43
THANK YOU
44