SQL to ER Diagram

Turn CREATE TABLE statements from PostgreSQL, MySQL, SQLite or SQL Server into an entity relationship diagram with keys, as SVG and Mermaid code.

Processed on your device. Files are not uploaded

How to make an ER diagram from SQL

  1. Paste your CREATE TABLE statements

    Paste or type your CREATE TABLE statements into the box, or press Try an example.

  2. Look at the diagram

    Tables, columns, keys and relationships are drawn.

  3. Download or copy

    Save the SVG, or copy the Mermaid code into your docs.

Worked example

This is what SQL to ER Diagram gives for its own sample values. Open the tool above and change anything to try your own.

CREATE TABLE statements

CREATE TABLE customers (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) NOT NULL UNIQUE,
  name TEXT NOT NULL,
  created_at TIMESTAMP DEFAULT now()
);

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  customer_id INT NOT NULL REFERENCES customers(id),
  status VARCHAR(20) NOT NULL,
  total NUMERIC(10, 2)
);

...
Show columns
Yes
Theme
Neutral

Mermaid code (paste into Markdown, Notion or Mermaid Editor)

erDiagram
  customers {
    SERIAL id PK
    VARCHAR(255) email UK
    TEXT name
    TIMESTAMP created_at
  }
  orders {
    SERIAL id PK
    INT customer_id FK
    VARCHAR(20) status
    NUMERIC(10_2) total
  }
  products {
...

Result

Tables
4
Relationships
orders.customer_id -> customers.id; order_items.order_id -> orders.id; order_items.product_id -> products.id

When to use SQL to ER Diagram

You joined a project and want a picture of how the database tables relate before reading the code.

Design docs or a pull request need an up-to-date diagram of a schema change.

Tips for a better SQL to ER Diagram result

Export the schema only, without data, so the input is small and every table is included.

Turn off columns for very large schemas to see the relationships clearly, then turn them on for the part you care about.

SQL to ER Diagram: limits and what to check

Relationships that exist only in application code, without a foreign key in SQL, cannot be seen and are not drawn.

Views, triggers and stored procedures are skipped, since they are not tables with columns and keys.

About SQL to ER Diagram

See the shape of a database at a glance. Tables, columns, types, primary keys, unique keys and foreign keys are read from CREATE TABLE and ALTER TABLE statements written for PostgreSQL, MySQL, SQLite or SQL Server, and drawn as an entity relationship diagram with crow's foot notation.

FAQs

How do I get the SQL from my database?

pg_dump --schema-only for PostgreSQL, mysqldump --no-data for MySQL, or .schema in the SQLite shell.

How is the relationship type chosen?

A required foreign key gives exactly one; a nullable one gives zero or one. A unique foreign key gives one to one.

Can I edit the diagram?

Copy the Mermaid code into Mermaid Diagram Editor and change it there.

Related tools