DBMS - Unit 3 (Relational Database Design)
DBMS - Unit 3 (Relational Database Design)
Relational DataBase
Design
Unit III Contents
●
Relational Model: Basic concepts, Attributes and Domains,
CODD's Rules.
●
Relational Integrity: Domain, Referential Integrities,
Enterprise Constraints.
●
Database Design: Features of Good Relational Designs,
Normalization, Atomic Domains and First Normal Form,
Decomposition using Functional Dependencies, Algorithms
for Decomposition, 2NF, 3NF,BCNF.
Dr. S.R.Khonde
Relational Model
The Relational model uses a collection of tables to
represent both data and the relationships among those data.
Tables are also known as relations.
Relation: made up of 2 parts:
Instance: a table, with rows and columns.
#rows =cardinality , #fields = degree / arity
Schema: specifies name of relation, plus name and type of
each column
E.g.: Students( sid: string, name: string, login: string,
age: integer, gpa: real)
Dr. S.R.Khonde
Relational Model Contd…
Dr. S.R.Khonde
Relational Model Contd…
Advantage:
Structural Independence
Its simple to navigate
Greater Flexibility
Better Security
Disadvantages
Performance
Data Complexity
Hardware and Software overhead
Physical Storage Consumption
Dr. S.R.Khonde
Components
The relational model consists of three major components
The set of relations and set of domains that defines the way
data can be represented (data structure)
Dr. S.R.Khonde
Codd's Rule
Dr. Edgar Frank Codd was a computer scientist while
working for IBM he invented the relational model for
database management.
Types of constraints
Domain Integrity Constraint
Entity Integrity Constraint
Referential Integrity Constraint
Enterprise Constraint
Dr. S.R.Khonde
Domain Integrity Constraint
The domain constraint are considered as the most basic
form of integrity constraints.
Constraints -
Not Null
Unique
Default
Check
Dr. S.R.Khonde
Entity Integrity Constraint
Primary Key Constraint –
It uniquely identify each record in a table
It does not allow NULL and duplicate values
Combination of Not Null and Unique
Dr. S.R.Khonde
Enterprise Constraint
It is also referred as Semantic Constraints.
They are additional rules specified by users or database
administrators.
These rules are depending upon the requirements and
constraints of the business for which the database system
is being maintained.
Dr. S.R.Khonde
Relational Database Design
Basic elements of design process:
Dr. S.R.Khonde
Features of Good Relational Design
Reduce redundancy
Easy access to data
More accuracy and integrity of information
Data entry, updates and deletions should be efficient.
Dr. S.R.Khonde
Normalization
Normalization is a database design technique which is
used to organize the tables in such a manner that it should
reduce redundancy and dependency of data.
It divides larger tables to smaller tables and links these
smaller tables using their relationships.
Types of Normalization-
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
Fourth Normal Form (4NF) Dr. S.R.Khonde
Decomposition
Definition -
The decomposition of a relation schema
R = {A1,A2,...,An}
is its replacement by a set of relation schemes
{R1, R2, ..., Rm}
such that
Ri⊆R for 1≤ i ≤ m
and R1 ∪ R2 ∪.... ∪ Rm = R
Dr. S.R.Khonde
Decomposition Example
R = { Emp_no, name, salary, branch_no, branch_add}
Decompose into
Dr. S.R.Khonde
Decomposition Example
STDINF ={Name,Course,Ph_No,Major,Prof,Grade}
Decompose
Dr. S.R.Khonde
Functional Dependency
The attributes of a relation is said to be dependent on
each other when an attribute of a table uniquely
identifies another attribute of the same table. This is
called functional dependency.
Dr. S.R.Khonde
Functional Dependency
R = { Emp_no, name, salary, branch_no, branch_add}
Dr. S.R.Khonde
Inference or Armstrong's Axioms
F1 : Reflexivity : x → x
F2 : Augmentation :
x → y |= xz → yz
F3 : Transitivity :
x → y and y → z |= x → z
F4 : Additivity :
x →y and x →z |= x → yz
F5 : Projectivity :
x → yz |= x → y and x → z
F6 : Pseudotransitivity :
x → y and yz → w |= xz → w
Dr. S.R.Khonde
Example
Eg – R=(A,B,C,D) and F = {A →B, A→C, BC→D}
Dr. S.R.Khonde
Closure of Functional Dependency
The set of functional dependencies and all logically implied
functional dependencies form a closure of F.
Denoted by F+
Dr. S.R.Khonde
Closure of Attribute Set
It is a set of all attributes that are dependent on X and derived
using the FDs in F.
Denoted by X+
Algorithm to compute X+
X+ = X (where X is candidate key)
while (changes to X+ ) do
for each FD w → z in F do
begin
if w ⊆ X+ then
X+ = X+ ∪ z
end Dr. S.R.Khonde
Dependencies
Full Functional Dependency
Given a relation schema R and an FD x → y ,
y is fully functionally dependent on x
if there is no z,
where z is proper subset of x
such that z → y
Eg – F = { ab → c , b → c } where ab is CK
As c is depend on subset b
So c is not fully functionally dependent on ab
Dr. S.R.Khonde
Dependencies
Partial Dependency
Given an relation R with the functional dependencies F
defines on the attributes of R and
K as a candidate key,
if X is a proper subset of K and if F |= X → A ,
then A is said to be partially dependent on K.
Eg – F = { ab → c , b → c }
If ab is candidate key
Then as c is depend on subset b
So c is partially dependent on b
Dr. S.R.Khonde
Dependencies
Transitive Dependency
Dr. S.R.Khonde
Example
R={ name, course, grade, ph_no, major, course_dept}
F = { course → course_dept
name → ph_no,
name → major,
name, course → grade }
Dr. S.R.Khonde
First Normal Form (1NF)
A relation is in First Normal Form if and only if the
domain of each attribute contains only atomic (indivisible)
values, and the value of each attribute contains only a
single value from that domain.
OR
An attribute (column) of a table cannot hold
multiple values.
It should hold only atomic values.
Dr. S.R.Khonde
First Normal Form (1NF)
Example: Suppose a company wants to store the names and contact
details of its employees.
emp_id emp_name emp_address emp_mobile
This table is not in 1NF as the rule says “each attribute of a table must have atomic
(single) values”, the emp_mobile values for employees Jon & Lester violates that rule.
Dr. S.R.Khonde
First Normal Form (1NF)
emp_id emp_name emp_address emp_mobile
Dr. S.R.Khonde
Second Normal Form (2NF) Cont..
Consider relation
R = {stu_name, course, ph_no, dept, grade }
F = { stu_name,course → grade,
stu_name → ph_no,
stu_name → dept }
Dr. S.R.Khonde
Second Normal Form (2NF) Cont..
R={manufacturer,Model,Model_name, Manu_country}
F = {manufacturer,model → model_name,
manufacturer → manu_country }
Key = {manufacturer,model}
Is in 2NF?
Decompose -
Dr. S.R.Khonde
Third Normal Form (3NF) Cont..
R = {emp_id,emp_name,emp_zip,emp_city}
Key = {emp_id}
F = {emp_id → emp_name ,
emp_id → emp_zip,
emp_zip → emp_city }
Dr. S.R.Khonde
Third Normal Form (3NF) Cont..
R = {emp_id,emp_name,emp_zip,emp_city}
R1 = {emp_id,emp_name,emp_zip}
R2 = {emp_zip, emp_city}
Dr. S.R.Khonde
Third Normal Form (3NF) Cont..
Example -
R = {course,prof,room,room_cap,enroll_limit}
Key = {course}
F = { course → prof,
course → room,
course → enroll_limit,
room → room_cap,
room → enroll_limit }
Dr. S.R.Khonde
Boyce Code Normal Form (BCNF)
R = {emp_id,emp_dept, nationality, dept_type, dept_no }
Key = {emp_id}
F = { emp_id → emp_dept,
emp_id → nationality,
emp_dept →dept_type,
emp_dept → dept_no }
Dr. S.R.Khonde
Boyce Code Normal Form (BCNF)
Example
R = { author, nationality, book_title, category, no_of_pages}
Key = {author}
F = {author →nationality,
Author → book_title,
book_title → category,
book_title → no_of_pages }
Dr. S.R.Khonde
Decomposition Algorithm
These are two important properties associated with
decomposition.
Lossless Join
Dependency Preservation
Dr. S.R.Khonde
Decomposition Algorithm
Lossless Join -
A decomposition of a relation R into schemes Ri (1 ≤ i ≤n)
is said to be a lossless join decomposition or simply
lossless if for every relation (R) the natural join of the
projections of R gives the original relation R; i.e.,
R = R1 ⋈ R2 ⋈ ... ⋈ Rn
Dr. S.R.Khonde
Decomposition Algorithm
Example: R
Model Price Category
Name
a11 100 Canon
s20 200 Nikon
a70 150 Canon
Dr. S.R.Khonde
Decomposition Algorithm
R1 ⋈ R2 Model Price Category
Name
a11 100 Canon
a11 150 Canon
s20 200 Nikon
a70 100 Canon
a70 150 Canon
Dr. S.R.Khonde
Decomposition Theorem
A decomposition of relation R<(x,y,z),F> into R1<(x,y),F1>
and R2 <(x,z),F2> is:
Dr. S.R.Khonde
Decomposition Theorem
Example -
Let R(a,b,c) and F = {a→b }
Dr. S.R.Khonde
END OF UNIT III