Crash Course · Beginner → Advanced

ER Diagrams and Data Flow Diagrams: The Complete Crash Course

Learn to model data and processes using the LibraryHub example: entities, attributes, keys and relationships in an Entity-Relationship Diagram (ERD), cardinality and crow’s foot notation, converting an ERD into tables with SQL, normalisation basics, and Data Flow Diagrams at context level, level 0 and level 1.

Beginner → Advanced14 min readInterview Q&A

ERD vs DFD vs UML

ModelAnswersUsed by
ER DiagramWhat data is stored and how it is related?Database designers, analysts
Data Flow DiagramHow does data move through processes?Business and system analysts
UMLHow are objects structured and how do they behave?Software designers, developers

ERD Building Blocks

  • Entity — a thing we store data about: Member, Book, Loan, Author.
  • Attribute — a property: Book.title, Book.isbn. Types: simple, composite (address = street + city), derived (age from birth date), multivalued (phone numbers).
  • Relationship — how entities are linked: Member borrows Book.
  • Primary key (PK) — unique identifier: member_id.
  • Foreign key (FK) — a column that refers to another table’s PK: loan.member_id.
  • Weak entity — cannot be identified without its owner (BookCopy depends on Book).

Cardinality and Notation

CardinalityMeaningExample
One-to-one (1:1)Each A has at most one BMember — LibraryCard
One-to-many (1:N)One A has many BMember — Loan
Many-to-many (M:N)Many A relate to many BBook — Author

Crow’s foot notation (most common in industry): a line ends with | (one), O (zero/optional) or a three-pronged “crow’s foot” (many). E.g. Member ||——O< Loan means one member has zero or many loans.

Chen notation (academic): rectangles for entities, diamonds for relationships, ovals for attributes.

LibraryHub ERD Example

erDiagram
  MEMBER ||--o{ LOAN : makes
  BOOK_COPY ||--o{ LOAN : "is borrowed in"
  BOOK ||--|{ BOOK_COPY : has
  BOOK }o--o{ AUTHOR : "written by"
  MEMBER {
    int member_id PK
    string name
    string email
  }
  BOOK {
    string isbn PK
    string title
    int year
  }
  BOOK_COPY {
    int copy_id PK
    string isbn FK
    string status
  }
  LOAN {
    int loan_id PK
    int member_id FK
    int copy_id FK
    date loan_date
    date due_date
    date return_date
  }
  AUTHOR {
    int author_id PK
    string name
  }

Resolving M:N: relational databases cannot store many-to-many directly, so Book–Author becomes a junction (associative) table BOOK_AUTHOR(isbn, author_id).

Converting the ERD to SQL Tables

CREATE TABLE member (
  member_id  SERIAL PRIMARY KEY,
  name       VARCHAR(100) NOT NULL,
  email      VARCHAR(150) UNIQUE NOT NULL
);

CREATE TABLE book (
  isbn   VARCHAR(13) PRIMARY KEY,
  title  VARCHAR(200) NOT NULL,
  year   INT
);

CREATE TABLE book_copy (
  copy_id SERIAL PRIMARY KEY,
  isbn    VARCHAR(13) NOT NULL REFERENCES book(isbn),
  status  VARCHAR(20) DEFAULT 'Available'
);

CREATE TABLE loan (
  loan_id     SERIAL PRIMARY KEY,
  member_id   INT NOT NULL REFERENCES member(member_id),
  copy_id     INT NOT NULL REFERENCES book_copy(copy_id),
  loan_date   DATE NOT NULL,
  due_date    DATE NOT NULL,
  return_date DATE
);

CREATE TABLE author (
  author_id SERIAL PRIMARY KEY,
  name      VARCHAR(100) NOT NULL
);

CREATE TABLE book_author (           -- junction table for M:N
  isbn      VARCHAR(13) REFERENCES book(isbn),
  author_id INT REFERENCES author(author_id),
  PRIMARY KEY (isbn, author_id)
);

Normalisation Basics (1NF, 2NF, 3NF)

Normalisation organises tables to reduce duplicate data and update errors.

FormRuleLibraryHub fix
1NFAtomic values, no repeating groupsDo not store “Author1, Author2” in one column → BOOK_AUTHOR table
2NF1NF + every non-key column depends on the whole composite keyIn BOOK_AUTHOR(isbn, author_id, title), title depends only on isbn → move it to BOOK
3NF2NF + no non-key column depends on another non-key columnIn LOAN, storing member_email depends on member_id → keep email only in MEMBER

Data Flow Diagram (DFD) Symbols

SymbolShape (Gane–Sarson / Yourdon)LibraryHub example
External entityRectangleMember, Librarian, Payment Gateway
ProcessRounded rectangle / circle, numbered2.0 Manage Loans
Data storeOpen-ended rectangle, D1, D2…D1 Members, D2 Books, D3 Loans
Data flowLabelled arrow“loan request”, “due-date notice”

Context Diagram, Level 0 and Level 1

  • Context diagram — the whole system as one process with external entities and main flows. Member → (search, loan request, fine payment) → LibraryHub → (search results, confirmations, notices) → Member; LibraryHub ↔ Payment Gateway; Librarian → (book data) → LibraryHub.
  • Level 0 (system diagram) — the main processes: 1.0 Manage Members, 2.0 Search Catalogue, 3.0 Manage Loans, 4.0 Handle Fines, 5.0 Generate Reports, with data stores D1 Members, D2 Books, D3 Loans, D4 Fines.
  • Level 1 — one process broken down. 3.0 Manage Loans → 3.1 Validate Member, 3.2 Check Availability, 3.3 Record Loan, 3.4 Send Confirmation, 3.5 Record Return.

Naming differs by textbook: some call the context diagram “Level 0”. What matters is moving from one process to more detailed levels.

DFD Rules

  • Balancing: inputs and outputs of a parent process must match those of its child diagram.
  • Data cannot flow directly between two external entities, two data stores, or an entity and a store — a process must be in between.
  • Every process needs at least one input and one output (no “black holes” or “miracles”).
  • Label every flow with a noun (data), every process with a verb phrase.
  • DFDs show data movement, not control logic or timing — use activity or sequence diagrams for those.

Tools

  • draw.io, Lucidchart, Miro — ERD and DFD shapes.
  • dbdiagram.io, MySQL Workbench, pgAdmin ERD tool — design databases and generate SQL.
  • Mermaid erDiagram — text ERDs in docs and GitHub.

Key Takeaways

  • ERD = data structure; DFD = data movement.
  • Entities, attributes, relationships, PK and FK.
  • Cardinality 1:1, 1:N, M:N; resolve M:N with a junction table.
  • Normalise to 3NF to avoid duplication.
  • DFD symbols: entity, process, store, flow.
  • Context → level 0 → level 1; keep levels balanced.

Interview Questions

What is an ER diagram?

A diagram showing the entities a system stores data about, their attributes and the relationships between them, used to design databases.

What is the difference between a primary key and a foreign key?

A primary key uniquely identifies a row in its table; a foreign key is a column that references a primary key in another table.

How do you implement a many-to-many relationship?

With a junction table holding the primary keys of both related tables as foreign keys.

What is a weak entity?

An entity that cannot be uniquely identified by its own attributes and depends on an owner entity.

Explain 1NF, 2NF and 3NF briefly.

1NF: atomic values; 2NF: no partial dependency on a composite key; 3NF: no transitive dependency between non-key columns.

What are the four DFD components?

External entities, processes, data stores and data flows.

What is a context diagram?

The highest-level DFD showing the whole system as a single process with its external entities and data flows.

What is DFD balancing?

Ensuring that the inputs and outputs of a process match those of its lower-level decomposition.

Exam Quick Revision

  • ERD = data; DFD = data flow; UML = objects/behaviour.
  • PK unique; FK references.
  • 1:1, 1:N, M:N → junction table.
  • Crow’s foot: | one, O zero, fork many.
  • 1NF atomic, 2NF full key, 3NF no transitive.
  • DFD: entity, process, store, flow.
  • Context → level 0 → level 1; balance.
  • No entity↔entity or store↔store flows.

Continue Learning

Scroll to Top