Professional Documents
Culture Documents
Hemani Parikh
Lecturer, CE dept.,BIT
Informal Design Guidelines for
relation schemas
• Semantics of the relation attributes
– Design a relation schema so that it is easy to explain
its meaning. Do not combine attributes from multiple
entity types and relationship types into a single
relation.
• Redundant information in tuples and update
anomalies
– Design base relation schema with no anomalies, if any
are present, note them clearly and make sure that the
programs that update the database will operate
correctly.
Informal Design Guidelines for
relation schemas
• Null values in tuples
– As far as possible, avoid placing attributes in a base
relation whose values may frequently be null.
• Generation of spurious tuples
– Design relation schemas so that they can be joined
with equality conditions on attributes that are either
primary keys or foreign keys in a way that guarantees
that no spurious tuples are generated. Avoid relations
that contain matching attributes that are not (foreign
key, primary key) combinations, because joining on
such attributes may produce spurious tuples.
Tables:
• Employee:
– Ename, ssn, bdate, address, dnumber
• Department:
– Dname, dnumber, dmgrssn (fk)
• Dept_locations
– Dnumber (fk), dlocation
• Project
– Pname, pnumber, plocation, dnumber(fk)
• Works_on:
– Ssn(fk), pnumber(fk), hours
Tables:
• Emp_dept:
– Ename, ssn, bdate, address, dnumber, dname,
dmgrssn
• Emp_proj:
– Ssn, pnumber, hours, ename, pname, plocation
• Emp_locs:
– Ename, plocation
• Emp_proj1:
– Ssn, pnumber, hours, pname, plocation
Function dependencies
• Definition:
– 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 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]
– K is a superkey of R, if KR, i.e if t1[K]=t2[K] for any
two tuples t1 and t2, then, t1[R]=t2[R].
– FD specifies constraints that we cannot express with
superkeys.
Example
A B C D
a1 b1 c1 d1
a1 b2 c1 d2
a2 b2 c2 d2
a2 b3 c2 d3
a3 b3 c2 d4
Inference Rules for Functional
Dependencies
• An FD X Y is inferred from a set of dependencies F
specified on R if X Y holds in every legal relation r of
R, that is whenever r satisfies all dependencies in F,
XY also holds in r.
• 1 – reflexive rule – if Y is subset of X, then XY
• 2 – augmentation rule – XY implies XZYZ
• 3 – transitive rule – XY, YZ, then XZ
• 4 – decomposition or projective rule – XYZ then XY
and XZ
• 5 – union or additive rule – XY, XZ then XYZ
• 6 - Self-determination rule – AA
• 7 – composition rule – If XY and WZ then XWYZ
• 8 – pseudotransitive rule – XY, WYZ, WXZ
Trivial and non-trivial FDs
• IR1 generates dependencies that are
always true, such dependencies are called
trivial; formally, if Y is a subset of X then
FD XY is trivial otherwise it is non-trivial.
Inference Rules for Functional
Dependencies
• IR1 to IR3 – Armstrong’s Axioms - sound and complete
rules
• Sound – do not generate any incorrect FDs
• Complete – for a given set F of FDs, they allow us to
generate all F+.
• Set of dependencies that include F as well as all
dependencies that can be inferred from F, is called the
closure of F; denoted by F+.
• To determine additional FDs, first determine each set of
attributes X that appears as a left-hand side of some
functional dependency in S and then to determine set of
all attributes that are dependent of X, i.e closure of X
under S, X+.
Closure of functional dependency
• Algo : Compute F+
F+=F;
repeat
for each functional dependency f in F+
apply reflexivity and augmentation rules on f
add the resulting functional dependencies to
F+
for each pair of functional dependencies f1 and f2 in F+
if f1 and f2 can be combined using transitivity
add the resulting functional dependency to F+
until F+ does not change any further
Closure of set of attributes
• Algo: compute X+
result:=X;
while (changes to result) do
for each functional dependency YZ in F do
begin
if Y is subset of result then result :=
result U Z;
end