You are on page 1of 36

Entity-Relationship Diagrams (ERD)

Chapter 2
Entity-Relationship Diagram (ERD)
• An entity-relationship diagram (ERD) is a graphical
representation of the data model representing the proposed
database

2
Entity-Relationship Diagram (ERD)
• An ERD contains three components:

3
Entity-Relationship Diagram (ERD)
• Four goals of ER diagrams:
– Capture all required data
– Ensure data appears only once in the database design
– Does not include any data that is derived from other data already in
the data model
– Arrange data in the data model in a logical manner

4
Entity-Relationship Diagram (ERD)
• ER diagram answers the questions:
– What entities (person, place, or thing) are being represented?
– What attributes (characteristics of data) are stored about each entity?
– What are the relationships between the entities?
– What are the business rules that will determine the structure of the ED
diagram?
– Basically, what data do we want to capture and what are the business
rules surrounding that data

5
Steps to Create ER Diagram
Step Task
1 Identify entities
2 Identify attributes
3 Assign unique identifiers (UID) – primary key (PK)
4 Identify relationships
5 Identify relationship cardinality (and optionality)
6 Assign foreign keys
7 Name relationships
8 Eliminate many-to-many relationships (Chapter 3)
9 Normalize the database (Chapter 4)
10 Define data types (Chapter 5)
6
What is an Entity?
• "Something" of significance to the business about which data
must be captured
• Entity Characteristics:
– Usually a noun
– Singular form
– Upper case
• Examples: CUSTOMER, STUDENT, EMPLOYEE

7
What is an Entity?
• An Entity can be a(n):
– Person – example EMPLOYEE
– Place – example BUILDING
– Object – example PRODUCT
– Event – example CONCERT

• Entities can be:


– Tangible, like PERSON or PRODUCT
– Intangible, like SKILL LEVEL
– An event, like CONCERT 8
Entities have Instances
• An entity instance is a single occurrence of an entity
• Examples:
– STUDENT entity - each student is an instance or occurrence within the
STUDENT entity
– EMPLOYEE entity could have instances of hourly employees and salary
employees
– DEPARTMENT entity could have instances of engineering, planning,
accounting, IT

9
BDE Consulting Company
The database planning phase has been completed and the database
system has been approved

What's the next step?

Requirements Analysis – page 23


BDE Consulting Company
The Requirements Analysis phase is completed.

What is the first step in the creation of the ER Diagram?

Step 1: Identify Entities


BDE Consulting Company
Requirements Analysis
• What are the entities for BDE? That is, what does the company
want to store data about?
Step 1: Identify Entities
• A singular name (usually a noun)
• Capital letters in bold
• Entity name at the top inside the rectangle
Step 2: Identify Attributes
• An attribute:
– A specific piece of data that describes an entity
– Can only have one value at any one moment in time for each instance
in the entity
 attribute = color vs. value = "blue"
 attribute = type vs. value = "dog"
– The attribute value may change over time
– Usually, but not always, an entity has at least one attribute

14
BDE Consulting Company
Requirements Analysis
• BDE is divided into departments. Each department has a unique
department id and department name

• What are the attributes?


DEPARTMENT Attributes
• BDE is divided into departments. Each department has a unique
department id and department name
BDE Consulting Company
Requirements Analysis
• We also need to store data about our employees. Each
employee is assigned a unique employee id. In addition, we
store each employee's first name, last name, social security
number, and hire date.
• What are the attributes?
EMPLOYEE Attributes
Each employee is assigned a unique employee id. In addition, we
store each employee's first name, last name, birth date, gender,
social security number, date hired, and salary.
BDE Consulting Company
Requirements Analysis
For each job, we store the job id, job title, minimum salary, and maximum
salary

What are the attributes for the JOB entity?


JOB Attributes
For each job type, we store the job id, job title, minimum salary, and
maximum salary
Mandatory (Required) Attributes
• An attribute that must contain a value
• The value is mandatory or required
• Cannot be NULL
• Appears as bold in the entity rectangle

• Example:
– An EMPLOYEE entity must require a value for the employee id, first
name and last name attributes

21
Mandatory (Required) Attributes
• Appears as bold in the entity rectangle

22
Optional Attributes
• Attribute that may not have a value or is NULL (unknown)
• Example:
– An EMPLOYEE entity might contain an optional mobile number
• Appears in normal font in the entity

23
Multivalued Attributes
• An attribute that can have more than one value
– A customer may have more than 1 contact number (home, mobile,
office)
– An EMPLOYEE may have more than one dependent

• Consider later

24
Volatile and Derived Attributes
• A volatile attribute contains a value that constantly changes over
time:
– length_of_membership
– years_of_service
– age
• Would have to be updated constantly

25
Volatile and Derived Attributes
• A derived attribute
– Contains a value that can be calculated from existing attributes
– Not stored in the database, but computed when required
– length_of_membership can be calculated using the current date and
membership_date attribute
– years_of_service can be calculated using current date and hire_date
attribute
– Age can be calculated using the current date and birth date

26
Nonvolatile Attributes
• Attributes that rarely change
• Examples:
– Order date
– Birth date
– Hire date

• Select nonvolatile attributes. For example, use birth date instead


of age

27
Step 2: Define Attributes for
BDE Consulting Company
• Attributes are listed under the entity name in lower case
• Mandatory attributes in bold
• Optional attributes in normal font
• Words are joined with an underline
Step 3: Assign Unique Identifier (UID) /
Primary Key (PK)
• Every entity must have a unique identifier or primary key
• Referred to as primary key in relational (physical) model and
database

29
Unique Identifier (UID)
• A single attribute or a combination of attributes
• Must be unique – Uniquely identifies one and only one instance
of an entity
• A unique identifier value should never change
• Must contain a value – cannot be NULL
• There should be no practical limit to the number of unique
identifier values available
• Only one unique identifier should be specified for each entity.
Remember, an UID can be one or more attributes
Candidate Keys
• Attributes that qualify as UIDs
• Each candidate key must meet the following criteria:
– Same rules as unique identifier
 Values must be unique for each instance within the entity
 Cannot contain a NULL value
Determine Candidate Keys
• Which attributes qualify as candidate keys?
Candidate Keys
• Candidate keys in red
Step 3: Identify Unique identifiers (UIDs)
• Listed as the first attribute in the box as PK (primary key)
• Must contain a unique value
• Is required and thus specified in bold
• Underlined
diagrams.net for Data Modeling
36

You might also like