Lecture2-ER_Design
Lecture2-ER_Design
o Notation
• Entity/ Weak entity
• Attributes
• Relationship
Reading material
• [GUW] Chapter 3
OPEN-SOURCE TOOLS
There are several open-source tools available for
drawing Entity-Relationship Diagrams (ERDs):
▪ draw.io
▪ Lucidchart
▪ dbdiagram.io
▪ MySQL Workbench
▪ Dia
▪ Pencil Project
A key is a set of attributes K for a relation R if
▪ In no instance of R will two different tuples agree on all
attributes of K
▪ That is, K can serve as a “tuple identifier”
Entity set
Relationship
Relationship set
Attributes
Member
Records fromDate
(when a user joined a group)
PURPOSE OF E/R
MODEL
▪ The E/R model allows us to sketch
database schema designs.
▪ Includes some constraints, but not
operations.
▪ Designs are pictures called entity-
relationship diagrams.
▪ Later: convert E/R designs to relational DB
designs.
FRAMEWORK FOR E/R
▪ Design is a serious business.
Entity Relationship Identifying and Determine the Determine key Cardinality Hierarchical
Identification Identification mapping value range for attribute for identification. design
(attributes or attributes to each attribute. each entity. (generalized/spe
entities) entities, cialized)
relationships. constraints.
Express the number of entities to which another entity can be associated
via a relationship set.
One to one
For a binary relationship set the
One to many
mapping cardinality must be one of Many to one
the following types: Many to many
One to one One to many
Beers
A relationship connects two or more It is represented by a diamond, with lines
entity sets. to each of the entity sets involved.
name addr Bars sell some name manf
beers.
license
Drinkers
name addr
Note: license = beer, full,
none
▪ The current “value” of an entity set is the set of entities
that belong to it.
▪ Example: the set of all bars in our database.
Beers
Bar Beer
Joe’s Bar Bud
Joe’s Bar Miller
Preferences
Drinkers
name addr
Bar Drinker Beer
Joe’s Bar Ann Miller
Sue’s Bar Ann Bud
Sue’s Bar Ann Pete’s Ale
Joe’s Bar Bob Bud
Joe’s Bar Bob Miller
Joe’s Bar Cal Miller
Sue’s Bar Cal Bud Lite
Focus: binary relationships, such as
Sells between Bars and Beers.
In a many-many
relationship, an entity E.g., a bar sells
many beers; a
of either set can be beer is sold by
connected to many many bars.
entities of the other set.
many-many
Some binary relationships are
many-one from one entity set to
another.
Favorite
Notice: two relationships connect the same entity sets, but are different.
1 2 3
Consider Best-seller Some beers are not the But a beer manufacturer
between Manfs and best-seller of any has to have a best-seller.
Beers. manufacturer, so a
rounded arrow to Manfs
would be inappropriate.
Best-
Manfs Beers
seller
EXAMPLE:
ATTRIBUTE ON price
RELATIONSHIP
Price is a function of both the bar and the beer,
not of one alone.
Create an entity set representing Make that entity set participate in
values of the attribute. the relationship.
Bars Sells Beers
Prices
price
Husband wife
Bob Ann
Joe Sue
… …
Married
husband wife
Drinkers
Relationship Set
Buddy1 Buddy2
Bob Ann
Joe Sue
Buddies Ann Bob
Joe Moe
1 2 … …
Drinkers
Subclass = special case = fewer entities = more
properties.
isa
EXAMPLE:
SUBCLASSES color Ales
Only a subset of entities within a type have
certain attributes or participate in certain
relationships
ID
STUDENT
GRAD_STUDENT Degrees
(o)verlap: may be more than one
(d)isjoint: entities may only be one subtype
A person must be
SSN exactly one: an
employee, an
PERSON alumnus, or a
student
d
U
EMPLOYEE ALUMNUS STUDENT
In contrast, E/R entities have
In OO, objects are in one class
representatives in all subclasses
only.
to which they belong.
• Subclasses inherit from • Rule: if entity e is represented
superclasses. in a subclass, then e is
represented in the superclass
(and recursively up the tree).
name Beers manf
Pete’s Ale
isa
color Ales
Underline the key attribute(s).
In an isa hierarchy, only the root entity set has a key, and it
must serve as the key for all entities in the hierarchy.
name Beers manf
isa
color Ales
dept number hours room
Courses
Plays-
Players Teams
on
manf
Beers
EXAMPLE
This design repeats the manufacturer’s address once for each beer and
loses the address if there are temporarily no beers for a manufacturer.
ENTITY SETS VERSUS
ATTRIBUTES
An entity set should satisfy at least one of the
following conditions:
▪ It is more than the name of
something; it has at least one non-
key attribute.
or
▪ It is the “many” in a many-one or
many-many relationship.
name name addr
EXAMPLE: GOOD
• Manfs deserves to be an entity set because of the non-key
attribute addr.
• Beers deserves to be an entity set because it is the “many” of the
many-one relationship ManfBy.
There is no need to make the manufacturer
an entity set, because we record nothing
about manufacturers besides their name.
name manf
Beers
name name
Since the manufacturer is nothing but a name, and is not at the “many”
end of any relationship, it should not be an entity set.
Beginning database designers They make all entity sets weak,
often doubt that anything could be supported by all other entity sets to
a key by itself. which they are linked.
population capital
county_name
county_area
In IsCapitalOf
name
Counties States
In name
area
ISA ISA
LocalTrains
LocalStations
ExpressTrains
ExpressStations
time No double-diamonds here
because train number + time
ExpressTrainStops
uniquely determine a stop
track of the direct supervisor of each employee (who is another FName Name Works_On Project
employee).
MI LName Hours
Salary
1
Supervisor Birthdate
Supervision
EMPLOYEE
Address
Supervisee
N
FName Name Works_On Project
MI LName Hours
Sex
REVISE!
Employee
DEPENDENT
DBirthdate
Relationship
DName
We want to keep track of the
dependents of each employee for
insurance purposes. We keep each
dependent’s first name, sex, birth
date, and relationship to the employee
Salary
Birthdate
EMPLOYEE
Address
Supervisee
N
FName Name Works_On Project
MI LName Hours
Salary
1
Supervisor
Birthdate
Supervision
EMPLOYEE
Address
1
N
Sex
MI LName Hours
DEPENDENT N
DEPENDENT DBirthdate
_OF
Relationship
DName
Name Number
DEPARTMENT
Location Manager ▪ A department controls a number of
projects, each of which has a unique
name, a unique number, and a single
location.
Manager_
Start_Date
Name Number
Location PROJECT
Controlling_
Department
Name Number
PROJECT
Location
N Name Number
1 DEPARTMENT
CONTROLS Manager
Manager_
Location Start_Date
Name Number
Location PROJECT
Name Number
N
CONTROLS
1 DEPARTMENT
Manager
Each department has a particular employee who
manages the department.
Location Manager_
Start_Date
An employee is assigned to one department, but
may work on several projects, which are not
Supervisor
Salary necessarily controlled by the same department. We
Sex Departmen
SSN
t
keep track of the current number of hours per week
Supervision
1
Birthdate that an employee works on each project.
EMPLOYEE
Address
N 1
Supervisee Name Works_On Project
M EMPLOYEE
WORKS_ON SSN
1 N
Name Start
_Date
N
PROJECT Manages
Location
Number
1
1 DEPARTMENT 1
CONTROLS Works_For
Name Number
Location
ALL TOGETHER
NOW!