Lesson 3

advertisement
DBS201 – Lesson 3
Agenda
A.
ERD: Review the Airline Reservation System or Produce an ERD for a
different System.
B.
Data Anomalies – The need for Normalization.
1) The Update Problem
2) The Data Inconsistency Problem
3) The Insertion Problem.
4) The Update Problem.
5) The Data Redundancy Problem. (Unnecessary Repetition of Data)
C.
NORMALIZATION: A Methodology for Database Design Used for Large
Databases.
A nine step process:
1)
Write Database Relations by inspecting User Views
(including Multi-Valued Dependencies)
2)
Convert Zero Normal Form Relations to First Normal Form.
3)
Convert First Normal Form Relations to Second Normal Form.
4)
Convert Second Normal Form Relations to Third Normal Form.
5)
Simplify Primary Keys When Possible
6)
Merge Relations
7)
Convert New Second Normal Form Relations to Third Normal Form.
8)
Identify all Foreign Keys
9)
Explode Attributes into Sub-Attributes
DBS201 – Lesson 3 – Page 1
3/9/2016
A.
Solving the Airline Reservation ERD problem.
a)
b)
c)
d)
e)
List the Entities
List the events occurring between Entities
Establish relationships as 1:1, 1:M or M:N
Show Cardinality using Crow’s Feet Notation
Draw the ERD
_________________________________________________________________.
a) List the Entities
RESERVATION(Reservation-ID , Seat Assignment)
SALESPERSON(Salesperson ID, Salesperson Name)
FLIGHT(Flight-ID , Date of Flight, Departure Location, Arrival Location,
Departure Time, Arrival Time)
PASSENGER(Passenger-ID , Passenger Name)
b) List the events which relate Entities to each other.
- Passenger makes a reservation
- Passenger takes a flight
- A Reservation reserves one flight for one person.
c) Establish relationships as 1:1, 1:M or M:N
Remember: We must consider the relationship as it exists within the
scope of the problem. Although there may be many chief executive
officers in the world, there is only one chief executive officer in one
company!
Chief Executive
Officer
1
Leads
M
Employees
Can one Chief Executive Officer lead many employees? Yes
Can one employee be led by more than one chief executive officer? We
will say No.
DBS201 – Lesson 3 – Page 2
3/9/2016
To Establish the cardinality we must answer two questions:
First: For 1 instance of the left hand entity, how many instances of the
right hand entity can exist? The answer is the Cardinality of the right-side
entity.
Second: For 1 instance if the right hand entity, how many instances of the
left hand entity can there be? The answer is the cardinality of the left-side
entity.
d)
Establish relationships as 1:1, 1:M or M:N (continued)
PASSENGER
PASSENGER
RESERVATION
e)
1
N
Makes
M
Takes
M
Reserves
For
RESERVATION
N
FLIGHT
1
FLIGHT
Show Cardinality using Crow’s Feet Notation
PASSENGER
Makes
c)
PASSENGER
Takes
RESERVATION
DBS201 – Lesson 3 – Page 3
Reserves
For
3/9/2016
RESERVATION
FLIGHT
FLIGHT
f)
Draw the ERD Diagram
PASSENGER
SALESPERSON
Makes
RESERVATION
Reserves
A seat
FLIGHT
DBS201 – Lesson 3 – Page 4
3/9/2016
B.
Why do we Normalize our data?
Experience has taught us that Normalization will avoid the following 5 problems.
Problem #1 with un-normalized data : The UPDATE problem: The need to
perform the same update in several locations of the database because the same
data is repeated.
(Ex)
STUDENT(Student-Num, Student-Name, Teacher, Student-Age)
1243658712
Tom Blu
Ms.Green 12
2343216578
Jill Fall
Mr.Brown 13
3214325436
Jack Pail
Ms.Green 12
In this un-normalized database if Ms.Green is replaced by Ms.White, we
will have to make more than one change to the database.
Problem #2 with un-normalized data – DATA INCONSISTENCY problem:
When the same data is repeated in several records, they can be inconsistent. In
the example below, which spelling is correct? Ms. Green or Ms. Greene
(Ex)
STUDENT(Student-Num, Student-Name, Teacher, Student-Age)
1243658712
Tom Blu
Ms.Greene 12
2343216578
Jill Fall
Mr.Brown 13
3214325436
Jack Pail
Ms.Green 12
Problem #3 with un-normalized data – the INSERT problem: Let us say we
have just hired a new teacher: Mr.Vert. We have no way to put him into the
database as he has no students yet.
No place
for Mr.Vert
Ex)
STUDENT(Student-Num, Student-Name, Teacher, Student-Age)
1243658712
Tom Blu
Ms.Greene 14
2343216578
Jill Fall
Mr.Brown 14
3214325436
Jack Pail
Ms.Green 14
Problem #4 with un-normalized data – the DELETION problem: If there is
no teacher table, and if a teacher’s students all go to high school, then the teacher
will disappear from our database.
(Ex) STUDENT(Student-Num, Student-Name, Teacher, Student-Age)
1243658712
Tom Blu
Ms.Greene 14
2343216578
Jill Fall
Mr.Brown 14
3214325436
Jack Pail
Ms.Green 14
DBS201 – Lesson 3 – Page 5
3/9/2016
Problem #5 with un-normalized data – DATA REDUNDANCY problem: the
unnecessary repetition of data in the database of non-key fields.
While it is fine to repeat Primary Keys and Foreign Keys, we do not want to
repeat data fields.
(Ex) STUDENT(Student-Num, Student-Name, Teacher, Student-Age)
1243658712
Tom Blu
Ms.Green 14
2343216578
Jill Fall
Mr.Brown 14
3214325436
Jack Pail
Ms.Green 14
DBS201 – Lesson 3 – Page 6
3/9/2016
C)
What is Normalization?
1)
Normalization:
a) a process by which we can define the best way to model the data in the domain
we are considering. In other words, Normalization is a way to design a database.
b) after normalization, we no longer have the data anomalies and redundancies
identified above.
c) the process identifies all the necessary tables with their attributes. It will allow
us to specify both Primary Keys and Foreign Keys.
2)
How do we Normalize?
We will Normalize our data records in nine steps producing flexible and powerful
data structures that are free of redundancies and data anomalies. Each table will
be cohesive. (all the attributes are assigned to the right table)
a)
UnNormalized Form: The relation has at least one multi-valued
dependancy
b)
1st Normal Form: Eliminate Multi-valued dependencies.
c)
2nd Normal Form: Eliminate Partial Dependencies
d)
3rd Normal Form: Eliminate Transitive Dependencies
***********************************************************************
DBS201 – Lesson 3 – Page 7
3/9/2016
Download