Database Notes Data Modeling and Entity Relationship Diagram
Database Notes Data Modeling and Entity Relationship Diagram
Diagram (ERD)
Data Modeling
Data modeling is a technique to document a software system using diagrams and symbols. It
is used to represent communication of data.
The highest level of abstraction for the data model is called the Entity Relationship Diagram
(ERD). It is a graphical representation of data requirements for a database.
1
Entity
Entities are the basic objects of ERDs. These are the tables of your database. Entity are nouns
and the types usually fall into five classes: concepts, locations, roles, events or things.
For example: students, courses, books, campus, employees, payment, projects.
Relationships
Relationships are the associations between the entities. Verbs often describe relationships
between entities. We will use Crow's Foot Symbols to represent the relationships. Three types
of relationships are discussed in this lab. If you read or hear cardinality ratios, it also refers to
types of relationships.
A single entity instance in one entity class is related to a single entity instance in another
entity class.
For example:
Each student fills one seat and one seat is assigned to only one student.
Each professor has one office space.
A single entity instance in one entity class (parent) is related to multiple entity instances in
another entity class (child)
For example:
One instructor can teach many courses, but one course can only be taught by one
instructor.
One instructor may teach many students in one class, but all the students have one
instructor for that class.
2
Each entity instance in one entity class is related to multiple entity instances in another entity
class; and vice versa.
For example:
Each student can take many classes, and each class can be taken by many students.
Each consumer can buy many products, and each product can be bought by many
consumers.
The detailed Crow's Foot Relationship symbols can be found here. Crow's Foot Relationship
Symbols
Many to many relationships are difficult to represent. We need to decompose a many to many
(M:M) relationship into two one-to-many (1:M) relationships.
Attributes
Attributes are facts or description of entities. They are also often nouns and become the
columns of the table. For example, for entity student, the attributes can be first name, last
name, email, address and phone numbers.
Primary Key
Foreign key
A foreign key+ (sometimes called a referencing key) is a key used to link two tables together.
Typically you take the primary key field from one table and insert it into the other table
where it becomes a foreign key (it remains a primary key in the original table). We can have
more than one foreign key in a table.
An Example
Here's a sample crowsfoot diagram from a past offering of CS270 taught here at the
University of Regina. We've redrawn the diagrams using more modern diagramming tools,
but the content is unchanged. It uses a lot of ERD symbols, so you might want to use Vivek
Chawla's quick guide while you read it.
3
Quick Questions
How many entities are there in this diagram and what are they?
What are the attributes for entity STUDENT?
What is the primary key for STUDENT?
What is the primary key for COURSE?
What foreign keys do STUDENT and COURSE contain?
4
Cardinality
Defines the numerical attributes of the relationship between two entities or entity sets.
One-to-One Relationships
One-to-Many Relationships
May to One Relationships
Many-to-Many Relationships
1.One-to-one:
One entity from entity set X can be associated with at most one entity of entity set Y and vice
versa.
Example: One student can register for numerous courses. However, all those courses have a
single line back to that one student.
5
2.One-to-many:
One entity from entity set X can be associated with multiple entities of entity set Y, but an
entity from entity set Y can be associated with at least one entity.
3. Many to One
More than one entity from entity set X can be associated with at most one entity of entity set
Y. However, an entity from entity set X may or may not be associated with more than one
entity from entity set X.
4. Many to Many:
One entity from X can be associated with more than one entity from Y and vice versa.
For example, Students as a group are associated with multiple faculty members, and faculty
members can be associated with multiple students.
6
ERD symbols and notations
There are several notation systems, which are similar but vary in a few specifics.
7
8
9
10
11
12
13