This sample models the core of an online shop: customers place orders, orders contain line items, each line points at a product, and products are grouped into a category tree. It uses crow's foot notation, the most common way to draw an entity-relationship (ER) diagram.
The line ends tell you how many rows on one side can relate to rows on the other, which is exactly what foreign keys and NOT NULL constraints will later enforce.
1. The Diagram
The diagram has five entities and five relationships. Read each line twice, once from each end.
Start at customer. The line to orders has two bars on the customer side (exactly one) and a circle plus crow's foot on the orders side (zero or many): a new customer can exist with no orders, but no order exists without a customer.
orders to order_item is one-to-one-or-many. An order with zero lines is not allowed, which the application enforces at checkout.
order_item has a composite primary key (order_id, line_no). order_id is also a foreign key, so the line cannot outlive its order.
product to order_item: a product may never have been sold (zero or many lines), but each line names exactly one product.
category classifies products, and its parent_id loop makes a category tree. The circle on the parent end means top-level categories have no parent.
Unique keys (UK) mark natural identifiers such as email and sku that must not repeat even though the surrogate key is the PK.
2. How to Read It
Each relationship line ends in two symbols. The symbol closest to the entity is the maximum (bar = one, crow's foot = many); the outer symbol is the minimum (circle = zero/optional, bar = one/mandatory). Inside each box, PK marks the primary key, FK a foreign key and UK a unique key. Verbs on the lines read left to right or top to bottom.
3. Variant: Resolving Many-to-Many
Conceptually an order contains many products and a product is in many orders. Relational databases cannot store a many-to-many line, so the logical model adds order_item as a junction (associative) entity. It also becomes a natural home for facts about the pairing, such as quantity and the price actually charged.
4. Pros, Cons, and When to Use
Pros
Line ends show both minimum and maximum cardinality at a glance.
Maps one-to-one onto tables, primary keys and foreign keys.
The most widely recognised ER style; used by most modelling tools.
Compact: attributes live inside the box, not in separate ovals.
Rendered natively by Mermaid, dbdiagram.io and draw.io.
Cons
Says nothing about behaviour, transactions or workflow.
Large schemas become wire tangles without subject-area splits.
Optionality is easy to get backwards when reading from the wrong end.
Business rules beyond cardinality (stock cannot go negative) need notes or constraints.
When to use
Designing or reviewing an OLTP schema before writing DDL.
Onboarding developers to an existing database.
Agreeing business rules such as "can an order be empty?"
When not to use
Analytical models (use a star schema diagram).
Showing request flow between services (use a sequence diagram).
5. As Diagrams-as-Code
MermaiderDiagram uses the same crow's foot symbols in text form:
erDiagram
customer ||--o{ orders : places
orders ||--|{ order_item : contains
product ||--o{ order_item : "sold as"
category ||--o{ product : classifies
category |o--o{ category : "parent of"
customer {
bigint customer_id PK
varchar email UK
varchar full_name
}
orders {
bigint order_id PK
bigint customer_id FK
date order_date
varchar status
}
order_item {
bigint order_id PK, FK
int line_no PK
bigint product_id FK
int quantity
decimal unit_price
}
dbdiagram.io (DBML) and PlantUML's entity syntax express the same model.