Dbms 3
Dbms 3
NIT Rourkela
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 1 / 35
Outline
2 Functional Dependencies
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 2 / 35
Relational Database Design
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 3 / 35
Functional Dependencies
Functional Dependencies
Functional Dependency:
A functional dependency, denoted by X −→ Y, between two sets of attributes X and Y that are
subsets of R specifies a constraint on the possible tuples that can form a relation state r of R.
The constraint is that, for any two tuples t1 and t2 in r that have t1 [X] = t2 [X], they must
also have t1 [Y] = t2 [Y].
Armstrong’s axioms:
Reflexivity rule: If X is a set of attributes and Y ⊆ X ,then X −→ Y holds.
Augmentation rule: If X −→ Y holds and Z is a set of attributes, then ZX −→ ZY holds.
Transitivity rule: If X −→ Y holds and Y −→ Z holds, then X −→ Z holds.
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 4 / 35
Functional Dependencies
Functional Dependencies
Armstrong’s axioms are sound and complete. These inference axioms can be derived from
Armstrong’s axioms.
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 5 / 35
Functional Dependencies
Functional Dependencies
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 6 / 35
Functional Dependencies
Functional Dependencies
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 7 / 35
Functional Dependencies
Functional Dependencies
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 8 / 35
Functional Dependencies
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 9 / 35
Closure of functional dependency set
The set of ALL FDs implied by a given set F of FDs is called the closure of F, and denoted as
F+ .
Armstrong Axioms can be applied repeatedly to infer all FDs implied by a set F of FDs.
We already read that Armstrong axioms are sound and complete. The exact meaning is:
Sound: The axioms generate ONLY FDs in F+ when applied to a given set of FDs F.
Complete: The axioms, when repeatedly applied to a given set of FDs F, will generate ALL FDs
in F+ .
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 10 / 35
Closure of attribute set
Attribute Closure:
For a given FD set, closure of an attribute is the set of all the attributes in the relation that the
input attribute can determine by using inference axioms and given FD set. Closure of an
attribute A is denoted by {A}+ or (A)+ .
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 11 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 12 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 13 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 14 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 15 / 35
Closure of attribute set
Extraneous Attribute:
For a given FD set F, an attribute A is extraneous in X −→ Y if A can be removed from the left
side or right side of X −→ Y without altering the closure of F.
Let G = {A −→ BC, B −→ C, AB −→ D }
Attribute C is extraneous in the right side of A −→ BC
Attribute B is extraneous in the left side of AB −→ D
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 16 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 17 / 35
Closure of attribute set
Consider the relation TABLE PURCHASE DETAIL(Customer ID, Store ID, Purchase Location)
Check if the following functional dependencies are satisfied in the above relation:
Q1. Customer ID −→ Purchase Location
Q2. Store ID −→ Purchase Location
Q3. {Customer ID, Store ID} −→ Purchase Location
Q4. Customer ID −→ Store ID
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 18 / 35
Closure of attribute set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 19 / 35
Redundancy in Functional Dependency Set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 20 / 35
Redundancy in Functional Dependency Set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 21 / 35
Redundancy in Functional Dependency Set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 22 / 35
Redundancy in Functional Dependency Set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 23 / 35
Redundancy in Functional Dependency Set
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 24 / 35
Redundancy in Functional Dependency Set
The set G found after removing ALL redundant FDs from F is called non-redundant cover of F.
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 25 / 35
Equivalence of functional dependency sets
Two sets of FDs F and G defined over same relation schema are equivalent iff
i. every FD in F can be inferred from G
AND
ii. every FD in G can be inferred from F
Two sets of FDs F and G defined over same relation schema are equivalent if F covers G and F
covers G
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 26 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
There can be many superkeys in a relation. A superkey is a set of attributes that has the
uniqueness property, but is not necessarily minimal.
candidate key is a minimal superkey, i.e. removing any attribute from a candidate key will not
retain its ability to uniquely determine other attributes.
Two properties of candidate key, or called just key, are unique and minimal.
If a relation has multiple keys, database designer specifies one of them to be the used as a key
while others won’t be. This specially selected key is called primary key.
The candidate keys which do not get elected as primary key are called alternate keys.
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 27 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 28 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Q. An instance of relational schema R(A,B,C) has distinct values for attribute A. Can you
conclude that A is a candidate key for R?
[GATE1994]
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 29 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Q. Relation R has eight attributes A,B,C,D,E,F,G,H. Fields of R contain only atomic values. F
= {CH -> G, A -> BC, B -> CFH, E -> A, F -> EG} is a set of functional dependencies
(FDs) so that F+ is exactly the set of FDs that hold for R. How many candidate keys does the
relation R have?
(a) 3
(b) 4
(c) 5
(d) 6
[GATE2013]
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 30 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 31 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Q. A Relation R with FD set {A -> BC, B -> A, A -> C, A -> D, D -> A}. How many
candidate keys will be there in R?
(a) 1
(b) 2
(c) 3
(d) 4
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 32 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Q. The maximum number of superkeys for the relation schema R(E,F,G,H) with E as the key is:
(a) 5
(b) 6
(c) 7
(d) 8
[GATE2014]
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 33 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 34 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 35 / 35
Superkeys, Candidate keys, Alternate Keys, and Primary key
Q. The following functional dependencies hold true for the relational schema R{V, W, X, Y, Z}:
V -> W; VW -> X; Y -> VX; Y -> Z
Which of the following is irreducible equivalent for this set of functional dependencies?
(a) {V -> W; V -> X; Y -> V; Y -> Z}
(b) {V -> W; W -> X; Y -> V; Y -> Z}
(c) {V -> W; V -> X; Y -> V; Y-> X; Y -> Z}
(d) {V -> W; W -> X; Y -> V; Y -> X; Y -> Z}
[GATE2017]
Dr. Sambit Bakshi (NIT Rourkela) Design Fundamentals January 25, 2019 36 / 35