liveBook · Manning

Entity-relationship diagram

As explained in Grokking Relational Database Design

An entity-relationship diagram is a visual model showing entities, their attributes, and the relationships between them, including relationship cardinalities.

An entity-relationship (E-R) diagram is a visual blueprint of a database. Boxes represent entities, lines represent relationships, and relationship symbols show rules such as cardinality. It models the schema, not the stored records: millions of rows still appear as one entity. section 5.2 section 3.10

Build a useful first draft in a few practical steps:

  • Turn requirements into simple subject-verb-object sentences, such as “A user makes purchases” and “A purchase contains products.” section 5.3
  • Treat the nouns as entities and connect pairs of entities related by the verbs. Leave attributes out of the first draft if they distract from the relationships. section 5.3 section 4.1
  • Assign each relationship a cardinality: one-to-one, one-to-many, or many-to-many. In Crow’s Foot notation, a crow’s foot marks the many side. section 5.10 section 5.5
  • Resolve many-to-many relationships with a junction table containing both entities’ primary keys, then review weak entities and foreign-key placement. section 5.10

The Sci-Fi Collective store

Start with users, purchases, products, reviews, and payment methods. Connect User to Purchase because a user can make multiple purchases while each purchase belongs to one user. Connect Purchase to Product because each purchase can contain several products and each product can appear in multiple purchases; represent that many-to-many relationship through a junction table. Similarly, connect User to Review and Product to Review, while requiring that a user bought a product before reviewing it. section 5.3 section 5.10

Inspect the visual model to see entities as boxes and relationships as connecting lines. section 5.2

How Grokking Relational Database Design covers it

How deep it goes
Develops entities, relationships, cardinalities, junction tables, and weak entities, but defers normalization and detailed attributes.
Examples
Uses an online store with users, purchases, products, reviews, payment methods, and a purchase-product junction table.
What it assumes
Assumes gathered requirements and identified entities while teaching data modeling, attributes, keys, data types, and relationships.
What you can do after
Build it from scratch by translating requirements into entities, connections, cardinalities, and relationship-supporting tables.
How it connects
Connects data modeling, entities, attributes, keys, cardinality, foreign keys, normalization, and database schemas.

Also explained in

Compare how 4 books explain entity-relationship diagram →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.