ER Model
ER Model
• Most real world datasets are so large that we can only have a small
fraction of them in main memory at any time, the rest has to stay on
disk.
• With a DBMS I can search with much more expressive queries. For
example I can ask.. “Find all students whose GPA is greater than
2.5, and who don’t own a phone” or “what is the average GPA of the
students”
Query Expressiveness II
• I could write some program that might allow more expressive
queries on my text file, but it would tied into the structure of my data
and the operating system etc..
•An entity set is a set of entities of the same type (e.g., all persons
having an account at a bank).
•Entity sets need not be disjoint. For example, the entity set Student
(all students in a university) and the entity set professor (all
professors in a university) may have members in common. (I.e a
computer science professor might take a class in anthropology).
Entities and Entity Sets Continued
• An entity is represented by a set of attributes. (E.g. name, S.S.N.,
Phone-Num for “customer” entity.)
• The domain of the attribute is the set of permitted values (e.g. the
telephone number must be seven positive integers).
S.S.N Street
name City
Students
Note that this is a poor example of a entity, since the name is represented as
one attribute and there is no street number attribute.
We will consider the problem of designing good entities later, here we are
just concerned with explaining their graphical representation.
Also note that one of the attributes is underlined, we will explain why later.
E-R diagrams Continued
We can express the overall logical structure of a database
graphically with an E-R diagram.
since
name name
Is
Men Married Women
to
Is Married to
This diagram is not a part of the ER model! It
is just an intuitive picture to explain a
concept
Key Constraints: Examples
•One-to-many: An entity in A is associated with any number in B.
An entity in B is associated with at most one entity in A.
A women may be the mother of many (or no) children. A person may have
at most one mother.
Born on
name name
Is
Women's Low I.Q.
Club
Mother
of Club
Note that this example is not saying that Moe does not have a
year
name Capital
Was
Bowling Country
Born
Club
in
Was born in Note that we are not saying that the Sea Captain was not born in some country, he
almost certainly was, we just don’t know which country, or it is not in our Country
entity set.
Also note that we are not saying that no one was born in Ireland, it is just that no one in
Key Constraints: Examples
•Many-to-many: Entities in A and B are associated with any number
from each other.
Since
name name
Is
Girls Boys
Classmate
of
Is Classmate of
Key Constraints
• The arrow positioning is simple once you get it straight in your
mind, so do some examples. Think of the arrow head as pointing to
the entity that “one‘” refers to.
• Some people call use the term “Mapping Cardinalities” to refer to
key constraints.
Participation Constraints
Earlier we saw an example of a one-to-one key constraint, noting that a man
may be married to at most one women, and woman may be married to at
most one man (both men and women can be unmarried).
Suppose we want to build a database for the “Springfield Christian Married
Persons Association”. In this case everyone must be married! In database
terms their participation must be total. (the previous case that allows
unmarried people is said to have partial participation.
How do we represent this with ER diagrams? (answer on next slide)
since
name name
Is
Men Married Women
to
Is Married to
Participation Constraints Cont.
Participation Constraints are indicated by bold lines in ER
diagrams.
We can use bold lines (to indicate participation constraints), and arrow lines (to
indicate key constraints) independently of each other to create an expressive
language of possibilities.
since
name name
Is
Men Married Women
to
Is Married to
More on Relations
• Entities sets can be related to themselves.
We can annotate the roles played by the
entities in this case. Suppose that we
want to pair a mature student with a
novice student...
Course # Course #
name name
If we are going to do calculations on the data (I.e calculate the BMI) we would
be much better off with just the height in inches. (medical records)
Team Team
Member Member
Entity versus Attribute
Sometimes we have to decide whether a property of the world we
want to model should be an attribute of an entity, or an entity set
which is related to the attribute by a relationship set.
Expires
Name SID
A better choice, but it only allows a student to have
one address. Many students have a two or more
Student
address (I.e. a different address during the summer
months) This method cannot handle this.
Num Street City
What is the correct domain for human age? (consider a bible database)
What is the correct domain for Phone Number? (What about foreign … )
Name S.S.N
We can see that {Name,S.S.N} is a
Lisa 1272 superkey
Name S.S.N
Bart 5592 In this example, S.S.N. is a
candidate key, as it is minimal, and
Student Lisa 7552 uniquely identifies a students
entity.
Sue 5592
Keys Cont.
•A primary key is a candidate key (there may be more than one) chosen by the DB
designer to identify entities in an entity set.
Auto
In the example below there are two different sections of C++ being offered (lets
say, for example, one by Dr. Keogh, one by Dr. Lee).
Name Number
C++ CS12
Java CS11
C++ CS12
Course
LISP CS15
Keys Cont.
In order to be able to uniquely refer to an item in a weak entity set we must
consider some (or all) of it’s attributes in conjunction with some strong entities
primary key. The entity whose primary key is being used is called the identifying
owner.
Why not remove the job entity by placing the title and level attributes as part of employee?
Ternary Relationships
Sometimes you have a choice of a single ternary
relationship or two binary relationships…
In general, unless you really
need a ternary relationship, Name SSN
use binary relationships.
Name SSN
FemalePatient
Is_Mother? Num_Children
Study Suggestion
It is tempting to think you understand the many concepts introduced
here because you understand the examples. To fully understand
reinforce your understanding, you should try to come up with
several more examples of each concept.
• Think up 3 examples of a many to one relationship
• Think up 3 examples of a weak entity set.
• Think up 3 examples of a …