0% found this document useful (0 votes)
5 views24 pages

Lecture 5.1

Notes of lecture 5.1

Uploaded by

arunavkg01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views24 pages

Lecture 5.1

Notes of lecture 5.1

Uploaded by

arunavkg01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Module 21

Partha Pratim
Das

Week Recap

Objectives &
Database Management Systems
Outline
Module 21: Relational Database Design/1
Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains Partha Pratim Das


and First Normal
Form

Module Summary
Department of Computer Science and Engineering
Indian Institute of Technology, Kharagpur

[email protected]

Database Management Systems Partha Pratim Das 21.1


Week Recap PPD

Module 21

Partha Pratim • Discussed relational algebra with examples


Das
• Introduced tuple relational and domain relational calculus
Week Recap

Objectives &
• Illustrated equivalence of algebra and calculus
Outline

Features of Good
• Introduced the Design Process for Database Systems
Relational Design
Redundancy and
• Elucidated the E-R Model for real world representation with entities, entity sets,
Anomaly
Decomposition
attributes, and relationships
Atomic Domains • Illustrated ER Diagram notation for ER Models
and First Normal
Form
• Discussed translation of ER Models to Relational Schema and extended features of ER
Module Summary
Model
• Deliberated on various design issues

Database Management Systems Partha Pratim Das 21.2


Module Objectives PPD

Module 21

Partha Pratim • To identify the features of good relational design


Das
• To familiarize with the First Normal Form
Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary

Database Management Systems Partha Pratim Das 21.3


Module Outline PPD

Module 21

Partha Pratim • Features of Good Relational Design


Das
• Atomic Domains and First Normal Form
Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary

Database Management Systems Partha Pratim Das 21.4


PPD

Module 21

Partha Pratim
Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary Features of Good Relational Design

Database Management Systems Partha Pratim Das 21.5


Good Relational Design

Module 21

Partha Pratim • Reflects real-world structure of the problem


Das
• Can represent all expected data over time
Week Recap

Objectives &
• Avoids redundant storage of data items
Outline

Features of Good
• Provides efficient access to data
Relational Design
Redundancy and
• Supports the maintenance of data integrity over time
Anomaly
Decomposition • Clean, consistent, and easy to understand
Atomic Domains
and First Normal • Note: These objectives are sometimes contradictory!
Form

Module Summary

Database Management Systems Partha Pratim Das 21.6


What is a Good Schema?
instructor
Module 21

Partha Pratim instructor with department


Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary department

• ID: Key
• building , budget: Redundant Information
• name, salary , dept name: No Redundant Information

Database Management Systems Partha Pratim Das 21.7


What is a Good Schema? (2)

Module 21

Partha Pratim • Consider combining relations


Das
◦ sec class(sec id, building, room number) and
Week Recap
◦ section(course id, sec id, semester, year)
Objectives &
Outline into one relation
Features of Good
Relational Design ◦ section(course id, sec id, semester, year, building, room number)
Redundancy and
Anomaly • No repetition in this case
Decomposition

Atomic Domains
and First Normal
Form

Module Summary

Database Management Systems Partha Pratim Das 21.8


Redundancy and Anomaly

Module 21

Partha Pratim • Redundancy: having multiple copies of same data in the database.
Das
◦ This problem arises when a database is not normalized
Week Recap
◦ It leads to anomalies
Objectives &
Outline • Anomaly: inconsistencies that can arise due to data changes in a database with
Features of Good
Relational Design
insertion, deletion, and update
Redundancy and
Anomaly ◦ These problems occur in poorly planned, un-normalised databases where all the data
Decomposition
is stored in one table (a flat-file database)
Atomic Domains
and First Normal There can be three kinds of anomalies
Form

Module Summary ◦ Insertions Anomaly


◦ Deletion Anomaly
◦ Update Anomaly

Database Management Systems Partha Pratim Das 21.9


Redundancy and Anomaly (2)

Module 21
• Insertions Anomaly
Partha Pratim
Das ◦ When the insertion of a data record is not possible without adding some additional
Week Recap
unrelated data to the record
Objectives &
◦ We cannot add an Instructor in instructor with department if the department does
Outline
not have a building or budget
Features of Good
Relational Design • Deletion Anomaly
Redundancy and
Anomaly
◦ When deletion of a data record results in losing some unrelated information that
Decomposition

Atomic Domains
was stored as part of the record that was deleted from a table
and First Normal
Form
◦ We delete the last Instructor of a Department from instructor with department, we
Module Summary
lose building and budget information
• Update Anomaly
◦ When a data is changed, which could involve many records having to be changed,
leading to the possibility of some changes being made incorrectly
◦ When the budget changes for a Department having large number of Instructors in
instructor with department application may miss some of them
Database Management Systems Partha Pratim Das 21.10
Redundancy and Anomaly (3)

Module 21 • We have observed the following:


Partha Pratim
Das
◦ Redundancy ⇒ Anomaly
◦ Relations instructor and department is better than instructor with department
Week Recap

Objectives &
• What causes redundancy?
Outline
◦ Dependency ⇒ Redundancy
Features of Good
Relational Design ◦ dept name uniquely decides building and budget. A department cannot have two
Redundancy and
Anomaly different budget or building. So building and budget depends on dept name
Decomposition

Atomic Domains
• How to remove, or at least minimize, redundancy?
and First Normal
Form ◦ Decompose (partition) the relation into smaller relations
Module Summary ◦ instructor with department can be decomposed into instructor and department
◦ Good Decomposition ⇒ Minimization of Dependency
• Is every decomposition good?
◦ No. It needs to preserve information, honour the dependencies, be efficient etc.
◦ Various schemes of normalization ensure good decomposition
◦ Normalization ⇒ Good Decomposition
Database Management Systems Partha Pratim Das 21.11
Decomposition

Module 21

Partha Pratim • Suppose we had started with inst dept. How would we know to split up (decompose)
Das
it into instructor and department?
Week Recap
• Write a rule “if there were a schema (dept name, building, budget), then dept name
Objectives &
Outline would be a candidate key”
Features of Good
Relational Design • Denote as a functional dependency: dept name → building, budget
Redundancy and
Anomaly • In inst dept, because dept name is not a candidate key, the building and budget of a
Decomposition
department may have to be repeated.
Atomic Domains
and First Normal
Form
◦ This indicates the need to decompose inst dept
Module Summary

Database Management Systems Partha Pratim Das 21.12


Decomposition (2)

Module 21

Partha Pratim • Not all decompositions are good


Das
• Suppose we decompose
Week Recap
employee(ID, name, street, city, salary) into
Objectives &
Outline employee1 (ID, name)
Features of Good
Relational Design
employee2 (name, street, city, salary)
Redundancy and
Anomaly
• Note that if name can be duplicate, then employee2 is a weak entity set and cannot
Decomposition
exist without an identifying relationship
Atomic Domains
and First Normal • Consequently, this decomposition cannot preserve the information
Form

Module Summary • The next slide shows how we lose information – we cannot reconstruct the original
employee relation – and so, this is a lossy decomposition.

Database Management Systems Partha Pratim Das 21.13


Decomposition (3): Lossy Decomposition PPD

Module 21

Partha Pratim
Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary

Database Management Systems Partha Pratim Das 21.14


Decomposition (4): Lossless-Join Decomposition

Module 21

Partha Pratim • Lossless Join Decomposition


Das
• Decomposition of R = (A, B, C)
Week Recap
R1 = (A, B), R2 = (B, C )
Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary

Database Management Systems Partha Pratim Das 21.15


Decomposition (5): Lossless-Join Decomposition

Module 21

Partha Pratim • Lossless Join Decomposition is a decomposition of a relation R into relations R1 , R2


Das
such that if we perform natural join of two smaller relations it will return the original
Week Recap relation
Objectives &
Outline
R1 ∪ R2 = R, R1 ∩ R2 6= φ
Features of Good
Relational Design ∀r ∈ R, r1 = uR1 (r ), r2 = uR2 (r )
Redundancy and
Anomaly
Decomposition
r1 ./ r2 = r
Atomic Domains
and First Normal • This is effective in removing redundancy from databases while preserving the original
Form
data
Module Summary
• In other words by lossless decomposition it becomes feasible to reconstruct the relation
R from decomposed tables R1 and R2 by using Joins

Database Management Systems Partha Pratim Das 21.16


PPD

Module 21

Partha Pratim
Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary Atomic Domains and First Normal Form

Database Management Systems Partha Pratim Das 21.17


First Normal Form (1NF) PPD

Module 21

Partha Pratim • A domain is atomic if its elements are considered to be indivisible units
Das
◦ Examples of non-atomic domains:
Week Recap

Objectives &
. Set of names, composite attributes
Outline . Identification numbers like CS101 that can be broken up into parts
Features of Good
Relational Design • A relational schema R is in First Normal Form (INF) if
Redundancy and
Anomaly ◦ the domains of all attributes of R are atomic
Decomposition
◦ the value of each attribute contains only a single value from that domain
Atomic Domains
and First Normal
Form • Non-atomic values complicate storage and encourage redundant (repeated) storage of
Module Summary data
◦ Example: Set of accounts stored with each customer, and set of owners stored with
each account
◦ We assume all relations are in first normal form

Database Management Systems Partha Pratim Das 21.18


First Normal Form (2)

Module 21

Partha Pratim • Atomicity is actually a property of how the elements of the domain are used
Das
◦ Strings would normally be considered indivisible
Week Recap
◦ Suppose that students are given roll numbers which are strings of the form CS0012
Objectives &
Outline or EE1127
Features of Good ◦ If the first two characters are extracted to find the department, the domain
Relational Design
Redundancy and of roll numbers is not atomic
Anomaly
Decomposition ◦ Doing so is a bad idea
Atomic Domains
and First Normal
. Leads to encoding of information in application program rather than in the
Form database
Module Summary

Database Management Systems Partha Pratim Das 21.19


First Normal Form (3) PPD

Module 21

Partha Pratim • The following is not in 1NF


Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition
◦ A telephone number is composite
Atomic Domains
and First Normal ◦ Telephone number is multi-valued
Form

Module Summary

Database Management Systems Partha Pratim Das 21.20


First Normal Form (4) PPD

Module 21

Partha Pratim • Consider:


Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly ◦ is in 1NF if telephone number is not considered composite
Decomposition

Atomic Domains
◦ However, conceptually, we have two attributes for the same concept
and First Normal
Form
. Arbitrary and meaningless ordering of attributes
Module Summary . How to search telephone numbers
. Why only two numbers?

Database Management Systems Partha Pratim Das 21.21


First Normal Form (5) PPD

Module 21

Partha Pratim • Is the following in 1NF?


Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains ◦ Duplicated information


and First Normal
Form ◦ ID is no more the key. Key is (ID, Telephone Number)
Module Summary

Database Management Systems Partha Pratim Das 21.22


First Normal Form (6) PPD

Module 21

Partha Pratim • Better to have 2 relations:


Das

Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains ◦ One-to-Many relationship between parent and child relations


and First Normal
Form ◦ Incidentally, satisfies 2NF and 3NF
Module Summary
• Decomposition helps to attain 1NF for the embedded one-to-many relationship

Database Management Systems Partha Pratim Das 21.23


Module Summary

Module 21

Partha Pratim • Identified the features of good relational design


Das
• Familiarized with the First Normal Form
Week Recap

Objectives &
Outline

Features of Good
Relational Design
Redundancy and
Anomaly
Decomposition

Atomic Domains
and First Normal
Form

Module Summary
Slides used in this presentation are borrowed from http://db-book.com/ with kind
permission of the authors.
Edited and new slides are marked with “PPD”.

Database Management Systems Partha Pratim Das 21.24

You might also like