Unit II (2) Object Oriented Programming
Unit II (2) Object Oriented Programming
Reference: Database System Concepts (6th edition) by Silberschatz A., Korth H.,Sudarshan
S.
Outline
Relational Model: Basic concepts, Attributes and Domains
Relational Integrity: Domain, Referential Integrities
CODD's Rules
Features of Good Relational Design
Atomic Domains and First Normal Form
Decomposition Using Functional Dependencies
Functional Dependency Theory
Normalization
Relational Model
Relational model stores data in the form of tables. This
concept
proposed by Dr. E.F. Codd, a researcher of IBM in the year 1960s.
The figure shows a relation with the. Formal names of the basic
components marked the entire structure is, as we have said, a
relation.
A single row of a table, which contains a single record for that relation
is called a tuple.. Actually, each row is an n-tuple, but the "n-" is
usually dropped.
Basic Terminology used in Relational Model
Keys are very important part of Relational database. They are used to
establish and identify relation between tables. They also ensure that
each record within a table can be uniquely identified by combination of
one or more fields within a table.
Super Key –
Candidate keys are defined as the set of fields from which primary key
can be selected. It is an attribute or set of attribute that can act as a
primary key for a table to uniquely identify each record in that table.
Primary Key
Primary Key
Candidate Key -
Example of employee table, EMPLOYEE_ID is best suited for primary
key as its from his own employer. Rest of the attributes like passport
number, SSN, license Number etc are considered as candidate key.
Basic Terminology used in Relational Model
Composite Key
Key that consist of two or more attributes that uniquely identify an entity
occurance is called Composite key. But any attribute that makes up the
Composite key is not a simple key in its own.
Basic Terminology used in Relational Model
Foreign key -
A foreign key is a field (or collection of fields) in one table that uniquely
identifies a row of another table or the same table. In simpler words, the
foreign key is defined in a second table, but it refers to the primary key
in the first table.
Basic Terminology used in Relational Model
Secondary or Alternative key
The candidate key which are not selected for primary key are known as
secondary keys or alternative keys
Non-key Attribute
Non-prime Attribute
Rule 6: View Updating Rule - All the views of a database, which can
theoretically be updated, must also be updatable by the system.
Functional Dependency
ABC → AB
ABC → A
ABC → ABC
Non Trivial Functional Dependencies
X → Y is a non trivial functional dependency when Y is not a subset of X.
X → Y is called completely non-trivial when X intersect Y is NULL.
Example:
Id → Name,
Name → DOB
Semi Non Trivial Functional Dependencies
X → Y is called semi non-trivial when X intersect Y is not NULL.
Examples:
AB → BC,
AD → DC
Combine Schemas?
Suppose we combine instructor and department into inst_dept
(No connection to relationship set inst_dept)
Result is possible repetition of information
A Combined Schema Without Repetition
Consider combining relations
sec_class(sec_id, building, room_number) and
section(course_id, sec_id, semester, year)
into one relation
section(course_id, sec_id, semester, year,
building, room_number)
No repetition in this case
What About Smaller Schemas?
Suppose we had started with inst_dept. How would we know to split up
(decompose) it into instructor and department?
Write a rule “if there were a schema (dept_name, building, budget), then
dept_name would be a candidate key”
Denote as a functional dependency:
A B C A B B C
1 A 1 1 A
2 B 2 2 B
r A,B(r) B,C(r)
A B C
A (r) B (r)
1 A
2 B
Functional Dependencies
Constraints on the set of legal relations.
Require that the value for a certain set of attributes determines
uniquely the value for another set of attributes.
A functional dependency is a generalization of the notion of a
key.
Functional Dependencies (Cont.)
Let R be a relation schema
R and R
The functional dependency
holds on R if and only if for any legal relations r(R), whenever any
two tuples t1 and t2 of r agree on the attributes , they also agree
on the attributes . That is,
t1[] = t2 [] t1[ ] = t2 [ ]
Example: Consider r(A,B ) with the following instance of r.
1 4
1 5
3 7
On this instance, A B does NOT hold, but B A does hold.
Functional Dependencies (Cont.)
K is a superkey for relation schema R if and only if K R
K is a candidate key for R if and only if
K R, and
for no K, R
Functional dependencies allow us to express constraints that cannot be
expressed using superkeys. Consider the schema:
inst_dept (ID, name, salary, dept_name, building, budget ).
We expect these functional dependencies to hold:
dept_name building
and ID building
but would not expect the following to hold:
dept_name salary
Use of Functional Dependencies
We use functional dependencies to:
test relations to see if they are legal under a given set of functional
dependencies.
If a relation r is legal under a set F of functional
dependencies, we say that r satisfies F.
specify constraints on the set of legal relations
We say that F holds on R if all legal relations on R satisfy the set
of functional dependencies F.
Note: A specific instance of a relation schema may satisfy a functional
dependency even if the functional dependency does not hold on all legal
instances.
For example, a specific instance of instructor may, by chance,
satisfy
name ID.
Functional Dependencies (Cont.)
A functional dependency is trivial if it is satisfied by all instances of a
relation
Example:
ID, name ID
name name
In general, is trivial if
Closure of a Set of Functional
Dependencies
Given a set F of functional dependencies, there are certain
other functional dependencies that are logically implied by F.
For example: If A B and B C, then we can
infer that A
C
The set of all functional dependencies logically implied by F is
the
closure of F.
We denote the closure of F by F+.
F+ is a superset of F.
Closure of a Set of Functional
Dependencies
Given a set F set of functional dependencies, there are certain other
functional dependencies that are logically implied by F.
For e.g.: If A B and B C, then we can infer that A C
The set of all functional dependencies logically implied by F is the
closure of F.
We denote the closure of F by F+.
Closure of a Set of Functional
Dependencies
We can find F+, the closure of F, by repeatedly applying
Armstrong’s Axioms:
if , then (reflexivity)
if , then (augmentation)
if , and , then (transitivity)
These rules are
sound (generate only functional dependencies that actually hold),
and
complete (generate all functional dependencies that hold).
Example
R = (A, B, C, G, H, I)
F={AB
AC
CG H
CG I
B
H}
some
members of
F+
AH
by
transi
tivity
from
A
B
and
B
H
Closure of Functional Dependencies
(Cont.)
Additional rules:
If holds and holds, then holds
(union)
If holds, then holds and holds
(decomposition)
If holds and holds, then
holds
(pseudotransitivity)
The above rules can be inferred from Armstrong’s axioms.
Closure of Attribute Sets
Given a set of attributes define the closure of under F (denoted
by +) as the set of attributes that are functionally determined by
under F
result := ;
while (changes to result) do
for each in F do
begin
if result then result := result
end
Example of Attribute Set Closure
R = (A, B, C, G, H, I)
F = {A B
AC
CG H
CG I
B H}
(AG)+
1. result =
2. AG
result = ABCG (A C and A B)
3. result = ABCGH (CG H and CG AGBC)
4. result = ABCGHI (CG I and CG
AGBCH)
Is AG a candidate key?
1. Is AG a super key?
1. Does AG R?
== Is (AG)+
R
2. Is any subset of AG a superkey?
1. Does A R? == Is (A)+ R
Canonical Cover
Sets of functional dependencies may have redundant dependencies
that can be inferred from the others
For example: A C is redundant in: {A B, B C,
A C}
Parts of a functional{Adependency
E.g.: on RHS: B, B may beredundant
C, A CD} can be simplified
to
{A B, B C, A D}
E.g.: on LHS: {A B, B C, AC D} can be simplified
to
{A B, B C,
A D}
Intuitively, a canonical cover of F is a “minimal” set of functional
dependencies equivalent to F, having no redundant dependencies or
redundant parts of dependencies
Canonical Cover
A canonical cover for F is a set of dependencies Fc such that
F logically implies all dependencies in Fc, and
Fc logically implies all dependencies in F, and
No functional dependency in Fc contains an extraneous attribute, and
Each left side of functional dependency in Fc is unique.
To compute a canonical cover for F:
repeat
Use the union rule to replace any dependencies in F
1 1 and 1 2 with 1 1 2
Find a functional dependency with an
extraneous attribute either in or in
/* Note: test for extraneous attributes done
using Fc, not F*/
If an extraneous attribute is found, delete it from
until F does not change
Note: Union rule may become applicable after some extraneous attributes
have been deleted, so it has to be re-applied
Multivalued Dependencies
Suppose we record names of children, and phone numbers for
instructors:
inst_child(ID, child_name)
inst_phone(ID, phone_number)
If we were to combine these schemas to get
inst_info(ID, child_name, phone_number)
Example data:
(99999, David, 512-555-1234)
(99999, David, 512-555-4321)
(99999, William, 512-555-1234)
(99999, William, 512-555-4321)
This relation is in BCNF
Why?
MVD (Cont.)
Tabular representation of
Example (Cont.)
In our example:
ID child_name
ID phone_number
The above formal definition is supposed to formalize the notion that given
a particular value of Y (ID) it has associated with it a set of values of Z
(child_name) and a set of values of W (phone_number), and these two
sets are in some sense independent of each other.
Note:
If Y Z then Y Z
Indeed we have (in above notation) Z1 = Z2
The claim follows.
Use of Multivalued Dependencies
We use multivalued dependencies in two ways:
III. Update anomalies: If one copy of such repeated data is updated, all copies need to
be updated to prevent inconsistency.
1 IS318 A
1 IS301 B
2 IS318 A
3 IS318 B
4 IS301 A
4 IS318 B
SID → S_name
SID S_name
1 Anand
2 Vijay
3 Shrikant
4 Vinay
CID → C_name
CID C_name Faculty F_phone
CID → F_Name
IS318 Database Shrikant 60192
IS301 Program Vikram 45869
3 IS318 B
4 IS301 A
4 IS318 B
SID S_name
1 Anand
2 Vijay
3 Shrikant
4 Vinay
CID C_name FID
IS318 Database 1
IS301 Program 2
IS318 Database 1
IS318 Database 1
2 Pradipkumar 45869
Grade (SID,CID,Grade)
Student (SID, S_name)
Course (CID, C_name, FID)
Faculty (FID, Faculty,
F_phone)