Course topics

By WebNest Studio Engineering Team

Database Design Tutorial

Tools for Database Design (ERD Software)

An Entity-Relationship Diagram (ERD) is a visual map of a database's tables, their columns, and how they relate to each other — one-to-many, many-to-many, and so on — drawn before (or alongside) the actual CREATE TABLE statements. ERD software turns this diagramming process from a manual whiteboard sketch into a structured, often auto-generating tool that can keep the diagram and the real schema in sync.

Sketching a schema visually before writing SQL is not busywork — it is one of the cheapest ways to catch a design mistake, because fixing a wrong relationship or a missing foreign key on a diagram takes seconds, while fixing the same mistake after a table already has real data and dependent application code can take hours or days.

Why it matters

A schema is far cheaper to change on a diagram than in a database full of data. Drawing the tables and their relationships first exposes missing entities and wrong relationships while they cost minutes to fix, and gives the team a picture to discuss. Diagrams written as text, such as DBML, can also be reviewed and versioned like code.

What ERD Tools Actually Do

At minimum, an ERD tool lets you draw boxes representing tables, list each table's columns and types inside the box, and draw lines between tables representing foreign key relationships, typically labeled with cardinality (one-to-one, one-to-many, many-to-many). More capable tools go further: they can generate working CREATE TABLE SQL directly from the diagram, or conversely reverse-engineer a diagram automatically from an existing database.

Common ERD Tools

Different tools suit different workflows, from lightweight sketching to tools tied directly to a specific database engine.

  • dbdiagram.io — a lightweight, code-based ERD tool where you describe tables and relationships in a simple text syntax (DBML) and it renders the diagram live; popular for quick, shareable schema sketches.
  • draw.io (diagrams.net) — a free general-purpose diagramming tool with ERD shape templates; flexible but fully manual, with no SQL generation.
  • pgAdmin's ERD view — built directly into pgAdmin for PostgreSQL; can generate a diagram from an existing database or design one and generate the SQL to create it.
  • MySQL Workbench — MySQL's official design tool, with a full visual schema designer that can forward-engineer a diagram into a real database or reverse-engineer an existing one into a diagram.

Why Diagramming First Catches Mistakes Early

Drawing the schema surfaces problems that are much harder to spot while staring at a list of CREATE TABLE statements one at a time: a relationship that should be many-to-many but was modeled as one-to-many, a missing junction table, a column that logically belongs on a different table, or a table that is trying to do the job of two separate entities. Reviewing a diagram with a teammate takes minutes; reviewing raw SQL DDL for the same issues takes much longer and misses more.

Example

A simple schema described in dbdiagram.io's DBML syntax

SQL
Table students {
  id int [pk, increment]
  name varchar
  email varchar
}

Table courses {
  id int [pk, increment]
  title varchar
}

Table enrollments {
  id int [pk, increment]
  student_id int [ref: > students.id]
  course_id int [ref: > courses.id]
  enrolled_on date
}
Output
dbdiagram.io renders three connected boxes: "students" and "courses" each linked to a middle "enrollments" table via one-to-many relationship lines, visually confirming that this is a many-to-many relationship between students and courses implemented correctly through a junction table — a mistake that would be much easier to overlook reading three separate CREATE TABLE statements in a row.

Common Mistakes

  • Skipping the diagram entirely on a "small" project and writing CREATE TABLE statements directly, only to discover a many-to-many relationship was modeled incorrectly after data and application code already depend on the wrong structure.
  • Letting the diagram and the real database schema drift out of sync over time by editing one without updating the other, which turns the diagram from a useful reference into a misleading one.
  • Choosing a heavyweight, database-specific tool (like MySQL Workbench) for a purely conceptual sketching phase, when a fast text-based tool like dbdiagram.io would let you iterate on the design more quickly.
  • Treating auto-generated CREATE TABLE SQL from an ERD tool as final without reviewing data types, constraints, and indexes, which the diagram usually represents only loosely.

Exercise

This exercise is written in DBML, the text format used by dbdiagram.io, so it does not run in the playground; paste it into dbdiagram.io to see the diagram. Describe two tables: users with an integer primary key id and a unique, required email; and posts with an integer primary key id, a title, and a user_id. Then declare that many posts belong to one user.

Expected result: a diagram with two tables joined by a one-to-many line from users to posts.

SQL · starter code
// TODO: Table users

// TODO: Table posts

// TODO: the reference from posts.user_id to users.id
Show hints
  • Column settings go in square brackets: id integer [pk], email varchar [unique, not null].
  • A many-to-one reference is written Ref: posts.user_id > users.id.
Show solution
SQL · solution
Table users {
  id integer [pk]
  email varchar [unique, not null]
}

Table posts {
  id integer [pk]
  title varchar
  user_id integer [not null]
}

Ref: posts.user_id > users.id

Quick quiz

1. What does an ER diagram show?

  • A. The speed of queries
  • B. The entities of a system, their attributes and the relationships between them
  • C. The rows stored in each table
  • D. The users connected to the database
Show answer

B. It is the design of the data, drawn before or alongside the tables.

2. Why draw the diagram before creating the tables?

  • A. Mistakes in the model are much cheaper to fix before data and code depend on them
  • B. The database requires it
  • C. Diagrams make queries faster
  • D. It replaces the need for constraints
Show answer

A. Changing a populated table means a migration and changes to every query that uses it.

3. What is an advantage of describing a schema as text, such as DBML?

  • A. It runs faster than SQL
  • B. It encrypts the schema
  • C. It needs no tables
  • D. It can be kept in version control and reviewed like code
Show answer

D. Changes to the design then show up as readable differences.

Interview questions

How do you approach designing a database for a new feature?

Show answer

Start from the requirements and the questions the system must answer. List the entities and their attributes, then the relationships and their cardinality, and draw them as an ER diagram. Review the diagram with the people who know the domain, since they spot missing rules. Then convert it to tables with keys, types and constraints, check it against the normal forms, and add indexes for the known query patterns.

What is the difference between a conceptual, a logical and a physical data model?

Show answer

A conceptual model names the main entities and relationships in business terms, with no technical detail. A logical model adds attributes, keys and normalised structure, still independent of any product. A physical model is the actual implementation for one database: table and column names, data types, indexes, partitioning. Design moves from the first to the last.

Key Points to Remember

  • ERD tools visually represent tables, columns, and relationships (including cardinality) before or alongside writing real SQL.
  • dbdiagram.io, draw.io, pgAdmin's ERD view, and MySQL Workbench are common choices, ranging from lightweight sketching to full database-integrated design.
  • Some tools can forward-generate SQL from a diagram or reverse-engineer a diagram from an existing database.
  • Reviewing a visual diagram catches relationship and structural mistakes far earlier and more cheaply than catching the same mistakes after the schema is already in production.

Practice in the playground

Write and run your own code for this topic, or start from the exercise or an example. Runs your SQL on SQLite in your browser. Standard SQL works; a few features that exist only in PostgreSQL or MySQL do not. Your code for each topic is kept in this browser.

Run the examples

Change an input, predict the result, then compare it with the output. Explain why the result changes.

These examples need a project environment on your computer, so they can be copied but not run here. Codelab runs Python, FastAPI backends with SQLite, plain Java 17 and HTML/CSS/JavaScript.

WebNest Studio

Written by

WebNest Studio Engineering Team

Practical lessons from developers working with Java, Python, React, databases and production systems.

Led by Vansh Duggal, Founder, WebNest Studio · Full-stack & software engineering