Entity-Relationship Diagrams (ERD) & Conceptual Data Modeling
Capture entities, attributes, and relationships before writing CREATE TABLE.
In plain words
Draw boxes for the things you store, list what you know about each, and draw lines showing how they connect, before writing any SQL.
Think of it like…
An architect's floor plan: rooms (entities), what's in them (attributes) and the doors between them (relationships) are agreed on paper before anyone pours concrete.
Where you’ve seen it
Designing a food-delivery app: Customer places many Orders; each Order comes from one Restaurant; an Order has many OrderItems, each referring to one MenuItem; a Rider delivers many Orders, and an Order has at most one Rider. The many-to-many between Order and MenuItem becomes the OrderItem table.
Words you’ll hear
- Entity
- A thing you store data about; usually becomes a table.
- Attribute
- A property of an entity; usually becomes a column.
- Cardinality
- How many of one entity relate to another: one-to-one, one-to-many, many-to-many.
- Crow's foot
- Notation where a three-pronged end means "many" and a circle means "optional".
Visual diagram
Theory & example queries
Finding entities and relationships
Read the requirements and underline nouns (customer, order, restaurant, rider): they're candidate entities. Things that are just properties of something else (customer's phone, order's total) are attributes. Verbs between nouns (places, contains, delivers) are candidate relationships.
For each relationship, ask how many on each side and whether it's required: can an order exist without a rider (yes, until assigned)? Can a customer have no orders (yes)? Those answers set the cardinality and optionality, which later decide where foreign keys go and whether they're nullable.
"How many restaurants can one order come from?" (one) "How many orders can one restaurant receive?" (many) → one-to-many, with restaurant_id on orders, NOT NULL.
From diagram to schema
The logical model adds primary keys to every entity, foreign keys on the many side of one-to-many relationships, and junction tables for many-to-many relationships (often with their own attributes, like quantity on order_items). The physical model then adds data types, constraints and indexes for a specific database.
Keep the ERD in sync with the real schema: many tools (dbdiagram.io, DBeaver, pgAdmin, draw.io) can draw it from DDL or generate DDL from it. In an interview, a quick sketch of 5–8 entities with their relationships and a word on keys is usually what's wanted before any CREATE TABLE.
| id | order_id | product_id | qty | price |
|---|---|---|---|---|
| 1 | 101 | 42 | 2 | 49.5 |
| 2 | 101 | 84 | 1 | 150 |
| 3 | 102 | 42 | 1 | 49.5 |
CREATE TABLE order_items ( order_id bigint REFERENCES orders (id), menu_item_id bigint REFERENCES menu_items (id), quantity int NOT NULL CHECK (quantity > 0), price_paid numeric(10, 2) NOT NULL, PRIMARY KEY (order_id, menu_item_id));PostgreSQL is the lesson baseline unless noted otherwise.
Identify the table or database object the statement will modify.
Expected output
Note: Representative PostgreSQL status when both referenced tables already exist.
Key takeaway: Conceptual → logical (keys, junctions) → physical (types, indexes).
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
List the entities
Pick out the nouns the system must remember, and drop ones that are only attributes of something else.
Customer · Restaurant · Order · MenuItem · Rider
When to use it & trade-offs
What it is
An Entity-Relationship Diagram (ERD) sketches a data model before any tables exist: entities (things like Customer, Order, Product) as boxes, their attributes (name, amount), and the relationships between them as lines marked with cardinality (one or many, optional or required), usually in crow's-foot notation. It moves from conceptual (what exists) to logical (keys and junction tables) to physical (actual tables and types).
Why it matters: Schema mistakes are expensive to fix once data and code depend on them. An ERD lets you agree the model with others in minutes and catch problems early, and in interviews, "design the database for X" is answered best by sketching entities and relationships first.
When to reach for it
- Starting any new schema or feature with new tables
- Schema-design interview questions
- Documenting an existing database for a team
When to avoid or be careful
- Writing CREATE TABLE before agreeing the entities and relationships
- Modelling many-to-many relationships with a single foreign key
- Letting the diagram drift out of date with the real schema
Conceptual vs logical vs physical models
Strengths: Simple boxes and lines; fast to change.
Watch out: No keys or types.
Strengths: Database-independent but precise.
Watch out: Not yet tuned for a specific engine.
Strengths: Types, constraints and indexes ready to create.
Watch out: Harder to discuss with non-engineers.
Interview signals & numbers to know
When this topic comes up
- “Design the database for an e-commerce / delivery / booking app”
- “What's an ERD?”
- “Explain cardinality”
- Crow's foot notation
- Data modelling
Benchmarks & rules of thumb
- 3
- levels: conceptual, logical, physical
- 3
- cardinalities: 1:1, 1:N, M:N
- 1
- junction table per many-to-many relationship
Common mistakes & follow-ups
Common interview mistakes
- Treating attributes (like address) as separate entities without a reason, or entities as attributes.
- Missing a many-to-many relationship, so an order can contain only one menu item.
- Skipping optionality, then making a foreign key NOT NULL that should allow "not yet assigned".
Likely interviewer follow-ups
- Draw an ERD for a library system with members, books and loans.
- How does a many-to-many relationship appear in the final tables?
- What's the difference between a conceptual and a physical model?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Entity-Relationship Diagrams (ERD) & Conceptual Data Modeling with hands-on SQL practice and interview Q&A.