0% found this document useful (0 votes)
82 views

Workbookdocx (1) PDF

1. The candidate keys for the relation R(ABCD) with functional dependencies {C → D, C → A, B → C} are C and BC. 2. The candidate keys for the relation R(ABCDEF) with functional dependencies {A → B, C → DF, AC → E, D → F} are AC and A. 3. The candidate keys for the relation R(ABCDEFGH) with functional dependencies {CH → G, A → BC, B → CFH, E → A, F → EG} are A and EFH.

Uploaded by

Md shadab Arshad
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)
82 views

Workbookdocx (1) PDF

1. The candidate keys for the relation R(ABCD) with functional dependencies {C → D, C → A, B → C} are C and BC. 2. The candidate keys for the relation R(ABCDEF) with functional dependencies {A → B, C → DF, AC → E, D → F} are AC and A. 3. The candidate keys for the relation R(ABCDEFGH) with functional dependencies {CH → G, A → BC, B → CFH, E → A, F → EG} are A and EFH.

Uploaded by

Md shadab Arshad
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/ 21

andiadate Keys are OrderNum and Partnum

Unit code​ -> Unit Name

Course code -​>Course name

Third Normal Form

A relation is in third normal form, if there is ​no transitive dependency​ for non-prime attributes
as well as it is in second normal form.

A relation is in 3NF if ​at least one of the following condition holds​ in every non-trivial
function dependency X –> Y

1. X is a super key.
Y is a prime attribute (each element of Y is part of some candidate key).​ Transitive
dependency

​If A->B and B->C are two FDs then A->C is called transitive dependency.

● Example 1 –​ In relation STUDENT given in Table 4,


FD set: {​ ​STUD_NO -> STUD_NAME​,
STUD_NO -> STUD_STATE​,
​STUD_STATE -> STUD_COUNTRY,
STUD_NO -> STUD_AGE}

Candidate Key: {STUD_NO}


For this relation in table 4, ​STUD_NO -> STUD_STATE and STUD_STATE ->
STUD_COUNTRY are true.
So ​STUD_COUNTRY is transitively dependent on STUD_NO​.
It violates the third normal form. To convert it in third normal form, we will decompose the relation
STUDENT (STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE,
STUD_COUNTRY_STUD_AGE)

1. STUDENT (STUD_NO, STUD_NAME, STUD_PHONE, STUD_STATE, STUD_AGE)

2. STATE_COUNTRY (STATE, COUNTRY)

EMP_ID EMP_NAME EMP_ZIP


EMP_ZI EMP_STATE EMP_CITY
P

1NF: R is in 1NF iff all domain values are atomic.


2NF: R is in 2 NF iff R is in 1NF and every nonkey attribute is fully dependent on
the key.
3NF: R is in 3NF iff R is 2NF and every nonkey attribute is non-transitively
dependent on the key

First Normal Form

roll_no name subject

101 Akon OS, CN

103 Ckon Java

102 Bkon C, C++


roll_no name subject

101 Akon OS

101 Akon CN

103 Ckon Java

102 Bkon C

Second Normal Form


Third Normal Form
Closure of an Attribute Set-
The set of all those attributes which can be functionally determined from an attribute set is called as a closure
of that attribute set.
● Closure of attribute set {X} is denoted as {X}​+​.
Example
Consider a relation R ( A , B , C , D , E , F , G ) with the functional dependencies-
A → BC
BC → DE
D→F BC+
CF → G
Now, let us find the closure of some attributes and attribute sets

Closure of attribute A-
D​+​ = {D }
= { D ,F } ( Using A → BC )
={A,B,C,D,E} ( Using BC → DE )
={A,B,C,D,E,F} ( Using D → F )
={A,B,C,D,E,F,G} ( Using CF → G )
Thus,
A​+​ = { A , B , C , D , E , F , G }

Closure of attribute D-

D​+​ = { D }
= { D , F } ( Using D → F )
We can not determine any other attribute using attributes D and F contained in the result set.
Thus,
D​+​ = { D , F }

Closure of attribute set {B, C}-

{ B , C }​+​= { B , C }
={B,C,D,E} ( Using BC → DE )
={B,C,D,E,F} ( Using D → F )
={B,C,D,E,F,G} ( Using CF → G )
Thus,
{ B , C }​+​ = { B , C , D , E , F , G }

​Closure of attribute set { C,F}-


{ C ,F }​+ ​= { C,F}
= { C , F , G}

Consider a relation R ( A , B , C , D) with the functional dependencies-


{ C → D, C → A , B → C}
Find Closure
C+ { C,D,A}
B+{B,​C D A}
Finding Candidate Keys-
​We can determine the candidate keys of a given relation using the following steps-
​Step-01:
Determine all essential attributes of the given relation.Essential attributes are those attributes which are not
present on RHS of any functional dependency.Essential attributes are always a part of every candidate key.This
is because they can not be determined by other attributes.
Example
Let R(A, B, C, D, E, F) be a relation scheme with the following functional dependencies-
A → B,
C → D,
D→E
Here, the attributes which are not present on RHS of any functional dependency are A, C and F.
So, essential attributes are- ​A, C and F​.

Step-02:
The remaining attributes of the relation are non-essential attributes. This is because they can be determined by
using essential attributes.
Now, following two cases are possible-
Case-01:
If all essential attributes together can determine all remaining non-essential attributes, then-
● The combination of essential attributes is the candidate key.
● It is the only possible candidate key.
Case-02:
If all essential attributes together cannot determine all remaining non-essential attributes, then-
● The set of essential attributes and some non-essential attributes will be the candidate key(s).
● In this case, multiple candidate keys are possible.
● To find the candidate keys, we check different combinations of essential and non-essential attributes.
Problem-01:
Let R = (A, B, C, D, E, F) be a relation scheme with the following dependencies-
C→F
E→A
EC → D
A→B
Essentails attributes {C E} +={ C ,E, F, A,B,D}
Which of the following is a key for R?
1. CD
2. EC
3. AE
4. AC

Step-01:
Determine all essential attributes of the given relation.
Essential attributes of the relation are- C and E.
So, attributes C and E will definitely be a part of every candidate key.

Step-02:
Now,
● We will check if the essential attributes together can determine all remaining non-essential attributes.
● To check, we find the closure of CE.
● So, we have-
● { CE }​+
● ={C,E}
● ={C,E,F} ( Using C → F )
● ={A,C,E,F} ( Using E → A )
● ={A,C,D,E,F} ( Using EC → D )
● ={A,B,C,D,E,F} ( Using A → B )

● We conclude that CE can determine all the attributes of the given relation.
● So, CE is the only possible candidate key of the relation.

Problem-02:
Let R = (A, B, C, D, E) be a relation scheme with the following dependencies-
AB → C
C→D
B→E
Determine the total number of candidate keys
So, we have-
{ AB }​+
={A,B}
={A,B,C} ( Using AB → C )
={A,B,C,D} ( Using C → D )
={A,B,C,D,E} ( Using B → E )

We conclude that AB can determine all the attributes of the given relation.
Thus, AB is the only possible candidate key of the relation.
Only one candidate key AB is possible.

Problem 03
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}
{E F H }+

What is the key for R?


1. { E, F }
2. { E, F, H }
3. { E, F, H, K, L }
4. { E }
we have-
{ EFH }​+
={E,F,H}
={E,F,G,H} ( Using EF → G )
={E,F,G,H,I,J} ( Using F → IJ )
={E,F,G,H,I,J,K,L} ( Using EH → KL )
={E,F,G,H,I,J,K,L,M} ( Using K → M )
= { E , F , G , H , I , J , K , L , M , N } ( Using L → N )

We conclude that EFH can determine all the attributes of the given relation.

So, EFH is the only possible candidate key of the relation.

Identify candidate keys for the following


1. R(ABCD) ​ FD- ​{ C → D, C → A, B → C}
2. R(ABCDEF) ​ FD- ​{ A → B, C →DF, AC → E, D →F }
3. R(ABCDEFGH) ​ FD- ​{ CH →G, A →BC, B →CFH, E →A, F →EG }
4. R(ABCD) ​ FD- ​{ AB→ C, BC → D, CD →A}
5. R(E, F, G, H, I, J, K, L, M, N) FD ={ EF → G ,F →I J, EH → KL, K → M, L→N}
6. R(ABCDEFGY) ​FD- ​{ AB→CD,D →CF,B →F, BYD →F,D →F,DE→F }
6. R(ABCD)​ FD- ​{ BC→ A, AD → B, CD →B,AC→D } KEYS are AC BC CD

7. Given a schema R( A, B, C, D, E), and the following set of FDs: {A​→​ E, E ​→​ CD, 
BC ​→​ A, D ​→ ​B}
LHS Due to the FDs Result becomes Description
A+ A→ E = AE (Reflexive) The  result  of  A+  is 
E→ CD = AECD (Transitive) equivalent to R.
D→ B = AECDB (Transitive) A is a candidate key.
= ABCDE
E+ E​→​ CD = ECD (Reflexive) E+ gives R.
D​→​ B = ECDB (Transitive) E is a candidate key.
BC​→​ A = ECDBA (Transitive)
= ABCDE
D+ = DB D​→​ B (Reflexive) D+  is  not  equivalent  to 
R.
D  is  not  a  candidate 
key.
B+  or  Neither  B  nor  C  alone  form  the  LHS  of  any  FDs.  Hence,  they 
C+ individually cannot form a candidate key.
So  far  we  have  tried  individual  (singleton)  attributes.  We  can  now  try  the 
combination  of  different  attributes. ​We  do not need to test the combination 
of attributes that have either A or E. The superset of either A or E cannot be 
a candidate key.
(BC)+ BC​→​ A = BCA (Reflexive) (BC)+  is  equivalent  to 
A​→​ E = BCAE (Transitive) R.
E​→​ CD = BCAED (Transitive) (BC) is a candidate key.
= ABCDE
(CD)+ D​→​ B = CDB (Reflexive) (CD)  is  a  candidate 
BC​→​ A = CDBA (Augment) key.
A​→​ E = CDBAE (Transitive)
= ABCDE
A, E, BC, and CD are the candidate keys of the relation R.

Equivalence of Two Sets of Functional Dependencies-


In DBMS,
● Two different sets of functional dependencies for a given relation may or may not be equivalent.
● If F and G are the two sets of functional dependencies, then following 3 cases are possible-

Case-01​: F covers G (F ​⊇​ G)


Case-02:​ G covers F (G ​⊇​ F)
Case-03:​ Both F and G cover each other (F = G)

Problem- 1
A relation R (A , C , D , E , H) is having two functional dependencies sets F and G as shown-Find whether
they are equivalent
​ ​F- ​{A → C, AC → D, E → AD,E → H}
​ G- { ​A → CD, E → AH}

F COVERS G G COVERS F
A+= {A CD} A+ ={ A C D}
E+= { E A H CD} AC+={AC D}
E+={ E AC D H}
Determining whether F covers G-
● (A)​+​ = { A , C , D } // closure of left side of A → CD using set F
● (E)​+​ = { A , C , D , E , H } // closure of left side of E → AH using set F

Thus, we conclude F covers G i.e. F ​⊇​ G

Determining whether G covers F-


● (A)​+​ = { A , C , D } // closure of left side of A → C using set G
● (AC)​+​ = { A , C , D } // closure of left side of AC → D using set G
● (E)​+​ = { A , C , D , E , H } // closure of left side of E → AD and E → H using set G

Determining whether both F and G cover each other-


From Step-01, we conclude F covers G.
From Step-02, we conclude G covers F.
Thus, we conclude both F and G cover each other i.e. F = G.

Problem 2

Given a relational schema R( A, B, C, D ) set of functional dependencies P and Q such that:

P = {A → B, B → C, C → D } and Q = { A → BC, C → D } using FD sets P and Q which of the following


options are correct?

a) P is a subset of Q

b) Q is a subset of P

c) P = Q

d) P ≠ Q

→Using definition of equivalence of FD set, let us determine the right-hand side of the FD set of P using FD set
Q.

Given P = { A → B, B → C, C → D } and Q = { A → BC, C → D }

Let us find closure of the left side of each FD of P using FD Q.

a. A+ = ABCD (using A → BC, C → D)


b. B+ = B (no FD of Q has B on its left)
c. C+ = CD (using C → D)

Now compare closure of each A, B and C calculated using FD Q with the right-hand side of FD P. Closure B is
B while in FD set P, B → C (B determines C), since the closure of B determined using FD Q has no C. Hence,
we can say ​P is not a subset of Q----------1

→Using definition of equivalence of FD set, let us determine the right-hand side of the FD set of Q using FD
set P.

Given P = { A → B, B → C, C → D } and Q = { A → BC, C → D }

Let us find closure of the left side of each FD of Q using FD P.

a. A+ = ABCD (using A → B, B → C, C → D)
b. C+ = CD (using C → D)
Now compare closure of each A and C calculated using FD P with the right-hand side of FD Q. Closure of each
A and C has all the attributes which are on the right-hand side of each FD of Q. Hence, we can say ​Q is a
subset of P-----------2

From 1 and 2 we can say that only Q is a subset of P since from 1 condition violated, hence option B is
correct ie ​ Q is a subset of P

Problem 3

Given a relational schema R( X, Y, Z ) set of functional dependencies P and Q such that:

P = { X → Y, Y → Z, Z → X } and Q = { X → YZ, Y → X, Z → X } using FD sets P and Q which of the


following options are correct?

a. P is a subset of Q
b. Q is a subset of P
c. P = Q
d. P ≠ Q

→Using definition of equivalence of FD set, let us determine the right-hand side of the FD set of P using FD set
Q.

Given P = {X → Y, Y → Z, Z → X} and Q = {X → YZ, Y → X, Z → X}

Let us find closure of the left side of each FD of P using FD Q.

a. X+ = XYZ (using X → YZ)


b. Y+ = YZX (using X → YZ, Y → X)
c. Z+ = ZXY (using X → YZ, Y → X, Z → X)

Now compare closure of each X, Y, Z calculated using FD Q with the right-hand side of FD P. Closure of each
X, Y, Z has all the attributes which are on the right-hand side of each FD of P. Hence, we can say ​P is a subset
of Q----------1

→Using definition of equivalence of FD set, let us determine the right-hand side of the FD set of Q using FD
set P.

Given P = { X → Y, Y → Z, Z → X } and Q = { X → YZ, Y → X, Z → X }

Let us find closure of the left side of each FD of Q using FD P.

a. X+ = XYZ (using X → Y, Y → Z, Z → X)
b. Y+ = YZX (using Y → Z, Z → X)
c. Z+ = ZXY (using X → Y, Y → Z, Z → X)

Now compare closure of each X, Y and Z calculated using FD P with the right-hand side of FD Q. Closure of
each X, Y and Z has all the attributes which are on the right-hand side of each FD of Q. Hence, we can say ​Q is
a subset of P-----------2
1. From 1 and 2 we can say that P = Q, option C is correct.​ P = Q

Problem 4

Suppose, a relational schema R (v w x y z) and set of functional dependencies F and G are as follow: F : { w​→
​ ​y, z​→​ wy, z​→​ v } G :{ w​→​ xy, z​→​ wx} Check the equivalency of functional dependencies F and G.
x, wx →

Problem 5
Suppose, a relational schema R (P,Q, R, S) and set of functional dependencies F and G are as follow:

F : { P ​→​Q, Q​→​ R, R ​→​S }

G : { P​→​ QR, R​→​ S } Check the equivalency of functional dependencies F and G.

Problem 1
The following functional dependencies hold true for the relational scheme R ( W , X , Y , Z ) –
X→W
WZ → XY
Y → WXZ
Write the irreducible equivalent for this set of functional dependencies.
Solution-
Step-01:
Write all the functional dependencies such that each contains exactly one attribute on its right side-
X→W
WZ → X
WZ → Y
Y→W
Y→X
Y→Z
Step-02:
Check the essentiality of each functional dependency one by one.
For X → W:
Considering X → W, (X)​+​ = { X , W }
● Ignoring X → W, (X)​+​ = { X }
Now,
● Clearly, the two results are different.
● Thus, we conclude that X → W is essential and cannot be eliminated.

For WZ → X:
Considering WZ → X, (WZ)​+​ = { W , X , Y , Z }
● Ignoring WZ → X, (WZ)​+​ = { W , X , Y , Z }

Now,
● Clearly, the two results are same.
● Thus, we conclude that WZ → X is non-essential and can be eliminated.

Eliminating WZ → X, our set of functional dependencies reduces to-


X→W
WZ → Y
Y→W
Y→X
Y→Z
Now, we will consider this reduced set in further checks.
For WZ → Y:
Considering WZ → Y, (WZ)​+​ = { W , X , Y , Z }
● Ignoring WZ → Y, (WZ)​+​ = { W , Z }

Now,
● Clearly, the two results are different.
● Thus, we conclude that WZ → Y is essential and cannot be eliminated.

For Y → W:
Considering Y → W, (Y)​+​ = { W , X , Y , Z }
● Ignoring Y → W, (Y)​+​ = { W , X , Y , Z }
Now,
● Clearly, the two results are same.
● Thus, we conclude that Y → W is non-essential and can be eliminated.
Eliminating Y → W, our set of functional dependencies reduces to-
X→W
WZ → Y
Y→X
Y→Z
For Y → X:
Considering Y → X, (Y)​+​ = { W , X , Y , Z }
● Ignoring Y → X, (Y)​+​ = { Y , Z }
Now,
● Clearly, the two results are different.
● Thus, we conclude that Y → X is essential and can not be eliminated.
For Y → Z:

● Considering Y → Z, (Y)​+​ = { W , X , Y , Z }
● Ignoring Y → Z, (Y)​+​ = { W , X , Y }
Now,
● Clearly, the two results are different.
● Thus, we conclude that Y → Z is essential and can not be eliminated.
From here, our essential functional dependencies are-
X→W
WZ → Y
Y→X
Y→Z
Step-03:
Consider the functional dependencies having more than one attribute on their left side.
Check if their left side can be reduced.
In our set,
● Only WZ → Y contains more than one attribute on its left side.
● Considering WZ → Y, (WZ)​+​ = { W , X , Y , Z }
Now,
● Consider all the possible subsets of WZ.
● Check if the closure result of any subset matches to the closure result of WZ.
(W)​+​ = { W }
(Z)​+​ = { Z }
Clearly,
● None of the subsets have the same closure result same as that of the entire left side.
● Thus, we conclude that we can not write WZ → Y as W → Y or Z → Y.
● Thus, set of functional dependencies obtained in step-02 is the canonical cover.
Finally, the canonical cover is-
Ans X → W, WZ → Y, Y → X, Y → Z

Problem 2
Find Minimal Cover for the following
F = {A → C, AB → C, C → DI, CD → I, EC → AB, EI → C}
1. Right Hand Side (RHS) of all FDs should be single attribute. So we write F as F1, as follows;

Problem 3
Consider the following set ​F​ of functional dependencies:
F= { A -​ >​ BC B ​->​ C A ​->​ B AB ​->​ C }
Ans F= ​ { A ​->​ B B ​->​ C​ ​}

Problem 4
F = { AB -> C, C -> A, BC -> D, ACD -> B, D -> E, D - > G, BE -> C, CG -> B, CG -> D, CE -> A, CE -> G}

Problem 5
Find the canonical cover of F = { A -> BC, B-> CE, A -> E, AC-> H, D -> B}
​Ans: Fc= { A -> BH, B-> CE, D-> B}

Problem 6
F = {A->BC, B ->CE, A ->E }
Ans F = { A ->B, B-> CE}

Problem 4
F = { AB -> C, C -> A, BC -> D, ACD -> B, D -> E, D - > G, BE -> C, CG -> B, CG -> D, CE -> A, CE -> G}

You might also like