DEV Community

Varun Krishnan
Varun Krishnan

Posted on Originally published at dbdiagramr.space AI-assisted

What Is an ER Diagram and How to Read One

The short version

An entity-relationship diagram is a picture of your database's tables, columns, and connections. You read it left to right: boxes are tables, lines are foreign-key relationships, and the symbols on each end tell you one-to-one, one-to-many, or many-to-many.

What each part means

Entities (tables)

Every box is a table. The bold name on top is the table name. The list underneath is the columns. Primary keys are usually marked with a key icon or bolded. Foreign keys have a link icon.

Example:

users
id (PK)
name
email
created_at

Attributes (columns)

Each line under the table name is a column. Common types you'll see:

  • id -- primary key (unique identifier)
  • name, email -- simple text fields
  • created_at -- timestamp of when the row was inserted
  • user_id -- foreign key pointing to another table (look for the line connecting it)

Relationships (lines)

Lines between boxes represent foreign key references. If you see a line from orders.user_id to users.id, that means "each order belongs to one user."

Cardinality (symbols)

The symbols at the end of each line tell you how many:

  • 1 -- ∞ (one to many): one user has many orders. This is the most common.
  • 1 -- 1 (one to one): one user has one profile.
  • ∞ -- ∞ (many to many): many users have many roles. Usually resolved with a join table.

Reading a real example

Suppose you see this diagram:

users ──1──∞── orders ──1──∞── order_items ──∞──1── products
   │
   1
   │
   ∞
addresses
Enter fullscreen mode Exit fullscreen mode

Reading left to right:

  1. One user has many orders.
  2. One order has many order items.
  3. One product appears in many order items.
  4. One user has many addresses.

The join table here is order_items ,it connects orders and products in a many-to-many relationship.

Why ER diagrams matter

  • Debugging: "Why is my query returning duplicates?" look for a missing join or unintended many-to-many.
  • Onboarding: New engineers understand the data model in 5 minutes instead of reading migration files.
  • Schema reviews: Spot missing indexes, redundant tables, or circular dependencies before they hit production.

Common mistakes

  1. Assuming every line is one-to-many. Check the symbols. A many-to-many without a join table is a red flag.
  2. Ignoring nullable columns. A dashed line or optional symbol means the relationship is optional.
  3. Forgetting to check the foreign key direction. orders.user_id → users.id is different from users.order_id → orders.id.

Try it yourself

Open your own database schema in dbdiagramr and trace the foreign keys. Start from the table you're most familiar with and follow the lines outward.

FAQ

What does PK mean in an ER diagram?

PK stands for primary key the unique identifier for each row in a table. It's usually id and is referenced by foreign keys in other tables.

What does FK mean?

FK stands for foreign key a column in one table that points to the primary key of another table. It creates the relationship between the two tables.

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

With a join table. For example, usersuser_rolesroles. The user_roles table holds user_id and role_id foreign keys, and the many-to-many becomes two one-to-many relationships.

What's the difference between an ER diagram and a schema diagram?

They're the same thing in practice. ER diagram is the academic term; schema diagram is the engineering term. Both show tables, columns, and relationships.

Do I need to draw an ER diagram by hand?

No. Tools like dbdiagramr generate ER diagrams automatically from your Supabase, Neon, or PostgreSQL connection string. Paste your connection string and get a visual schema in seconds.

Top comments (0)