An ER diagram (short for entity relationship diagram, also written ERD) is a diagram that shows the things a database stores, the details kept about each one, and how they relate to each other. The entity relationship model was introduced by Peter Chen in 1976 and is still the standard way to plan a relational database before building it.
Parts of an ER diagram
Entity: a thing the system keeps data about, such as Customer, Order or Product. In a database it becomes a table.
Attribute: a detail of an entity, such as name, email or price. It becomes a column.
Primary key: the attribute that identifies each record, such as a customer ID.
Foreign key: an attribute that points to the primary key of another entity.
Relationship: a line between two entities, labeled with how they are connected, such as "places" or "contains".
Cardinality in ER diagrams
Cardinality says how many records on one side can relate to records on the other:
One to one: each employee has one company badge.
One to many: one customer places many orders.
Many to many: a student takes many courses and a course has many students. In a database this is usually resolved with a linking table.
Crow's foot notation, the most common style, draws these with a single bar for "one" and a three pronged foot for "many".
Types of ER diagrams
Conceptual: only the main entities and relationships, for discussion with non technical stakeholders.
Logical: adds attributes and keys, without details of a particular database product.
Physical: adds data types, indexes and constraints, ready to be built.
How to draw an ER diagram
List the entities. Read the requirements and pick out the nouns the system must remember.
Add attributes and keys. Give each entity a primary key.
Connect the entities. Draw each relationship and name it.
Set the cardinality. Decide one or many on each end, and whether the relation is optional.
Resolve many to many relationships with linking entities, then review the model with the team.
Example
Sofia plans the database for a veterinary clinic. Her entities are Owner, Pet, Appointment and Vet. One owner has many pets, one pet has many appointments and each appointment is with one vet. Drawing the diagram shows that prescriptions need their own entity linked to appointments, a gap she finds before any table is created.
ER diagram vs other diagrams
An ER diagram describes stored data. A data flow diagram shows how that data moves through a system, and a class diagram, one of the UML diagrams, adds behavior to the data. An architecture diagram shows where the database sits in the whole system.
ER diagrams in MockFlow
Describe your data in a sentence and the AI database diagram generator drafts the tables and relationships on a MockFlow board. You can also begin with the entity relationship diagram template, use the database schema designer skill, or work through a design with the database schema architect concept builder. Teams review the model together on a whiteboard for developers.
