Professional Documents
Culture Documents
Chapter 02-1 Entities, Attributes, and UID
Chapter 02-1 Entities, Attributes, and UID
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?
– 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 unique keys
5 Identify relationships
6 Identify relationship cardinality (and optionality)
7 Assign foreign keys
8 Name relationships and ER language
9 Eliminate many-to-many relationships
10 Define data types
11 Normalize the database (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
9
Blackwater Consulting
The database planning phase has been completed and the database
system has been approved
17
Blackwater Consulting
Requirements Analysis
• Blackwater is divided into departments. Each department has a
unique department id and department name
• Example:
– An EMPLOYEE entity must require a value for the employee id, first
name and last name attributes
26
Mandatory (Required) Attributes
• Appears as bold in the entity rectangle
27
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
28
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
29
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
30
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
31
Nonvolatile Attributes
• Attributes that rarely change
• Examples:
– Order date
– Birth date
– Hire date
32
Step 2: Define Attributes for
Blackwater Consulting
• 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
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
34
Unique Identifier (UID) /
Primary Key (PK)
• 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/Primary Keys (PK)
• 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 identified by red rectangle
Step 3: Assign Unique Identifiers (UIDs)/
Primary Key (PK)
• 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 (Missing)
Step 4: Assign Unique Keys (UK)
• All candidate keys not selected as UID/PK
• Identified by UK
• Can contain a NULL value; thus can be an optional attribute
diagrams.net for Data Modeling
42