Database Modeling 2
Database Modeling 2
Database Modeling
Databases
Modeling
or
Data
representation
(of an enterprise)
Management of
the data
Levels of Abstraction in a
DBMS
End-user
Program
A
Program
B
Program
C
Use DML
Levels of Abstraction in a
DBMS
External Schema
End-user
View 1
Program
A
Program
B
Program
C
Use DML
View 1
Levels of Abstraction in a
DBMS
C
External Schema
End-user
View 1
Program
A
Program
B
Program
C
Use DML
View 1
O
N
C
E
P
T
U
A
L
S
C
H
E
M
A
Levels of Abstraction in a
DBMS
C
External Schema
End-user
View 1
Program
A
Program
B
Program
C
Use DML
View 1
O
N
C
E
P
T
U
A
L
S
C
H
E
M
A
Database:
Organized
according
to physical
schema.
Levels of Abstraction in a
DBMS
C
External Schema
End-user
View 1
Program
A
Program
B
Program
C
Use DML
View 1
O
N
C
E
P
T
U
A
L
Database:
Organized
according
to physical
schema.
S
C
H
E
M
A
Name
Address
Major
Name
Address
Major
12345
Alice
Chicago
CS
23456
Bob
Joliet
ECE
34567
Charles
Gary
CME
45678
Dan
Chicago
CS
Relationship
ENROLLMENT
STUDENT is enrolled in a COURSE
Relationship:
ENROLLMENT
STUDENT is enrolled in a COURSE during a
SEMESTER
ENROLLMENT:
Studentid
Name
Address
Major
12345
Alice
Chicago
CS
23456
Bob
Joliet
ECE
34567
Charles
Gary
CME
45678
Dan
Chicago
CS
Student-id
Course Name
Grade
12345
CS 480
12345
CS 401
34567
CME 508
Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM
Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM
Modeling Subtleties
Modeling choices will affect the usefulness
of the database system
Example:
Entity Sets: ITEMS, SUPPLIERS
Relationship: SUPPLIES
A SUPPLIER supplies an ITEM
ER Diagram
Example:
SUPPLIER
ITEM
ER Diagram
Example:
SUPPLIER
SUPPLIES
ITEM
ER Diagram
Example:
Weigh
t
Price
SUPPLIER
Supp.
Name
SUPPLIES
Supp.
Address
Color
ITEM
Item
Name
Representation of Ternary
Relationships
Course
Enrollmen
t
Semester
Student
Whats Next?
Observations about relationships
Functionality of Relationships
Special Types of Relationships
Existence
Is-a
Keys
Comprehensive Data Modeling
Example
Course
PreReq
Company
Database
Course
Employee
PreReq
Manages
Manages
Employee
Project
Work-on
Takes
Student
Course
TAs
Functionality of
Relationships
Mapping Cardinality Constraints
Express the number of entities to which
another entity can be associated via a
relationship set
Most useful in describing binary
relationship sets.
One to One
For each member of entity set A
there is at most one related member
of B.
Ex:
Men
Marriag
e
Women
One to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of B, there is at
most one member of A.
One to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of B, there is at
most one member of A.
Men
Fathers
Children
Many to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of entity set B,
there are zero or more related
member of A.
SUPPLIER
SUPPLIES
ITEM
Many to Many
For each member of entity set A,
there are zero or more related
members of B.
For each member of entity set B,
there are zero or more related
member of A.
SUPPLIER
SUPPLIES
ITEM
Course
Enrollmen
t
Student
Mapping Cardinality
Constraints
One to
one
One to many
Mapping Cardinality
Constraints
Many to
one
Many to many
Relationship Instance
A
Relationship Instance
A
Database Instance of R
Relationship Instance
A
Database Instance of R
Is it a possible instance of R?
Relationship Instance
A
Database Instance of R
Is it a possible instance of R?
Is R then One to One?
Relationship Instance
A
Database Instance of R
Is it a possible instance of R?
Is R then One to One?
Separation of Database Schema
and Database Instance
Existence Relationships
A one to many relationship set R,
between entity sets A and B
indicates existence-dependence
if an entity set of type B can exist in
the database only if it is related to an
entity of type A.
B is called a dominated entity set.
R is represented by:
B represented by:
Existence Relationships
A company wants to store information about the
children of employees.
Existence Relationships
A company wants to store information about the
children of employees.
SS#
Salary
Employee
Last
Name
Father
s
First
Name
Child
name
Birt
h
Date
Existence Relationships
In a university system: modeling courses and
their possible sections.
Semeste
r
Credit
s
Course
Cours
e
id
Course
-sec
Section
Year
Title
Section
id
Existence Relationships
Should Works-on be an existence relationship?
Employee
Works
on
Project
Existence Relationships
Should Works-on be an existence relationship?
Employee
Works
on
Project
Existence Relationships
A company wants to store information about the
children of employees.
SS#
Salary
Employee
Last
Name
IMPLICATIONS?
Father
s
First
Name
Child
name
Birt
h
Date
Existence Relationship
SS#
First
Name
Last
Name
Salary
12345
Alice
Allen
100K
23456
Bob
Barry
50K
34567
Charles
Cole
20K
45678
Dan
Dole
200K
Dads SS#
Child Name
Birthdate
12345
Amy
1/1/10
23456
Bill
2/2/09
12345
Andy
3/3/11
45678
Dave
4/4/07
45678
Dylan
5/5/05
Existence Relationship
SS#
First
Name
Last
Name
Salary
12345
Alice
Allen
100K
23456
Bob
Barry
50K
34567
Charles
Cole
20K
45678
Dan
Dole
200K
Dads SS#
Child Name
Birthdate
12345
Amy
1/1/10
23456
Bill
2/2/09
12345
Andy
3/3/11
45678
Dave
4/4/07
45678
Dylan
5/5/05
Existence Relationship
SS#
First
Name
Last
Name
Salary
23456
Bob
Barry
50K
34567
Charles
Cole
20K
45678
Dan
Dole
200K
Dads SS#
Child Name
Birthdate
12345
Amy
1/1/10
23456
Bill
2/2/09
12345
Andy
3/3/11
45678
Dave
4/4/07
45678
Dylan
5/5/05
Existence Relationship
SS#
First
Name
Last
Name
Salary
23456
Bob
Barry
50K
34567
Charles
Cole
20K
45678
Dan
Dole
200K
Dads SS#
Child Name
Birthdate
12345
Amy
1/1/10
23456
Bill
2/2/09
12345
Andy
3/3/11
45678
Dave
4/4/07
45678
Dylan
5/5/05
Existence Relationship
SS#
First
Name
Last
Name
Salary
23456
Bob
Barry
50K
34567
Charles
Cole
20K
45678
Dan
Dole
200K
Dads SS#
Child Name
Birthdate
23456
Bill
2/2/09
45678
Dave
4/4/07
45678
Dylan
5/5/05
ISA Relationship
If each entity in the entity set B is a
particular type of entity in entity set
A then we say that B isa A.
Namely, there is an ISA relationship
between A and B.
Specialization
Salary
Name
Address
Hospital
Employee
ISA
Physician
ISA
Specializatio
n
Work
Hours
Lab
Technician
Keys
Def: The key of an entity set E is a
minimal subset of the attributes of E
that uniquely indentifies an entity in
the set.
This subset of attributes adequately
distinguishes between elements of
the entity set.
Keys
name
address
Student
Studentid
Keys
Is {name}
a key?
name
address
Student
Studentid
Keys
Is {name}
a key?
name
address
Is {address}
a key?
Student
Studentid
Keys
Is {name}
a key?
name
address
Is {address}
a key?
s {student-id, address}
a key?
Student
Studentid
Keys
name
address
{student-id}
Minimal
Uniquely identifies
a student
Student
Studentid
Keys
name
address
{student-id}
Minimal
Uniquely identifies
a student
Student
Keys in the
ER-diagram are
underlined.
Studentid
Year
Salar
y
Middle
Initial
Actors
First
Name
Title
Movies
Starred-in
Last
Name
Lengt
h
Film Type
Year
Salar
y
Middle
Initial
Actors
First
Name
Title
Movies
Starred-in
Last
Name
Lengt
h
Film Type
Keys
Age
Year
Salar
y
Middle
Initial
Actors
First
Name
Title
Movies
Starred-in
Last
Name
Lengt
h
Film Type
Salary
Name
Hospital
Employee
ISA
Physician
Address
ISA
Specializatio
n
Work
Hours
Lab
Technician
Salary
Employee
Last
Name
Child
Father
s
First
Name
name
Birt
h
Date
Salary
Employee
Last
Name
Father
s
First
Name
Child
name
Birt
h
Date
Salary
Employee
Last
Name
Father
s
First
Name
Child
name
Birt
h
Date
Supplie
r
Id
Price
SUPPLIER
SUPPLIES
Color
PART
Part Id
Supp.
Name
Supp.
Address
Item
Name
Supplie
r
Id
Price
SUPPLIER
SUPPLIES
Color
PART
Part Id
Supp.
Name
Supp.
Address
Item
Name
Weigh
t
Price
Date
SUPPLIER
Color
PART
SHIPMEN
T
Part Id
Supp.
Name
Supp.
Address
Item
Name
Weigh
t
Price
Date
SUPPLIER
Color
PART
SUPPLIES
Part Id
Supp.
Name
Supp.
Address
Item
Name
Exercise ER-Diagram
Database System for an Airline to be
used for:
Booking Flights
Managing Flights, Crew Members, and
their Planes