DBMS - Unit 4
DBMS - Unit 4
It is not possible to insert employee details for an employee who has not been
assigned to any department. In such a case, we have to include NULL values.
Informal Design Guidelines for Relation Schemas
ii) Deletion Anomalies: This anomaly occurs if we delete from EMP_DEPT an
employee tuple that happens to represent the last employee working for a
particular department, the information concerning that department is also lost
inadvertently from the database.
It is easy to see that these three anomalies are undesirable and cause difficulties to
maintain consistency of data as well as require unnecessary updates that can be
avoided; hence, we can state the next guideline as follows.
Joining the above two relations using natural join, is going to result in generation
of some extra spurious tuples which amounts to incorrect information. This is
because, in this case, Plocation is the common attribute relating EMP_LOCS &
EMP_PROJ1, which is neither a primary key nor a foreign key.
Guideline 4. Design relation schemas so that they can be joined with equality
conditions on attributes that are appropriately related (primary key, foreign key)
pairs 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.
Functional Dependencies
Definition of Functional Dependency: A functional dependency is a constraint
between two sets of attributes from the database.
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].
This means that the values of the Y component of a tuple in r depend on, or are
determined by, the values of the X component; alternatively, the values of the X
component of a tuple uniquely (or functionally) determine the values of the Y
component.
We also say that there is a functional dependency from X to Y, or that Y is
functionally dependent on X. The abbreviation for functional dependency is FD.
The set of attributes X is called the left-hand side of the FD, and Y is called the
right-hand side.
Consider the relation schema EMP_PROJ, from the semantics of the attributes and
the relation, we know that the following functional dependencies should hold:
a. Ssn → Ename
b. Pnumber → {Pname, Plocation}
c. {Ssn, Pnumber} → Hours
Inference Rules for Functional Dependencies
Definition: An FD X → Y is inferred from or implied by a set of dependencies F
specified on R if X → Y holds in every legal relation state r of R; that is, whenever
r satisfies all the dependencies in F, X → Y also holds in r.
Informal Definition. Formally, the set of all dependencies that include F as well
as all dependencies that can be inferred from F is called the closure of F; it is
denoted by F+.
For example, suppose that we specify the following set F of obvious functional
dependencies on the relation schema EMP_PROJ1:
F = {Ssn → {Ename, Bdate, Address, Dnumber},
Dnumber → {Dname, Dmgr_ssn} }
Some of the additional functional dependencies that we can infer from F are the
following:
Ssn → {Dname, Dmgr_ssn}
Dnumber → Dname
Inference Rules for Functional Dependencies
The closure F+ of F is the set of all functional dependencies that can be inferred
from F. To determine a systematic way to infer dependencies, we must discover a
set. of inference rules that can be used to infer new dependencies from a given set
of dependencies. They were proposed first by Armstrong (1974) and hence are
known as Armstrong’s axioms.
As we can see, this is not in 1NF because Dlocations is not an atomic attribute,
as illustrated by the first tuple in the relation.
First Normal Form
There are three main techniques to achieve first normal form for such a relation:
1. Remove the attribute Dlocations that violates 1NF and place it in a separate
relation DEPT_LOCATIONS along with the primary key Dnumber of
DEPARTMENT. The primary key of this newly formed relation is the combination
{Dnumber, Dlocation}, as shown in the fig below. A distinct tuple in
DEPT_LOCATIONS exists for each location of a department. This decomposes
the non-1NF relation into two 1NF relations.
First Normal Form
2. Expand the key so that there will be a separate tuple in the original
DEPARTMENT relation for each location of a DEPARTMENT. In this case, the
primary key becomes the combination {Dnumber, Dlocation}. This solution has
the disadvantage of introducing redundancy in the relation and hence is rarely
adopted.
Eg: If {Ssn, Pno} Hrs is a full dependency, then neither {Ssn Hrs}
nor {Pno Hrs} holds.
Attribute Preservation: We must make sure that each attribute in R will appear in
at least one relation schema Ri in the decomposition so that no attributes are lost;
formally, we have
Eg: Car_Sales
MVD MVD
Note: If a relation schema is in 3NF and each of its keys consists of a single
attribute, it is also in 5NF.
Eg: Consider the SUPPLY relation & after decomposition we get R1, R2 & R3
relations: