SQL to ER diagram converter

Paste SQL CREATE TABLE statements and get a Mermaid entity relationship diagram with every table, column, primary key, foreign key and relationship. Free, works with most SQL dialects, and runs in your browser.

erDiagram
    customers ||--o{ orders : "customer_id"
    customers {
        serial id PK
        varchar(255) email UK
    }
    orders {
        serial id PK
        integer customer_id FK
        numeric(10_2) total
    }
Loading the tool…

How to do it

  1. Step 1

    Paste your schema

    Paste your CREATE TABLE statements, or upload a .sql dump.

  2. Step 2

    Pick the detail

    Choose whether to show columns or only tables.

  3. Step 3

    Review the diagram

    Check the ER diagram and the notes about anything that was skipped.

  4. Step 4

    Use it

    Copy the Mermaid, or open it in the editor to arrange and export it.

Keep the diagram in step with the schema

An ER diagram generated from the schema is always accurate on the day it is made, which hand-drawn ones rarely are a few months later. Paste the latest schema whenever it changes and commit the Mermaid next to your migrations, so reviewers see the model change in the diff.

Big schemas

Large schemas make crowded diagrams. Turn off "Show columns" to see only tables and relationships, or paste the tables for one area of the system at a time.

Reading the result

Each column is written as type name followed by its keys: PK for primary key, FK for foreign key and UK for unique. Relationship lines use crow's foot notation: || means exactly one, |o zero or one, and o{ zero or more.

What this does not do

  • Relationships come only from declared foreign keys. Tables joined by convention (a user_id column with no constraint) are not linked.
  • Composite foreign keys are drawn as one relationship labelled with all their columns.
  • Views, triggers, enums and CREATE TABLE … AS SELECT are skipped.

Frequently asked questions

Which SQL dialects are supported?

CREATE TABLE statements from PostgreSQL, MySQL and MariaDB, SQLite and SQL Server, including quoted names, schema-qualified names, inline and table-level PRIMARY KEY, UNIQUE and FOREIGN KEY constraints, and foreign keys added later with ALTER TABLE. Other statements, such as INSERT or CREATE INDEX, are ignored.

How do I get the schema SQL from my database?

Run pg_dump --schema-only for PostgreSQL, mysqldump --no-data for MySQL, or .schema in the sqlite3 shell, and paste the output. Most database GUIs also have "Copy DDL" or "Generate SQL" for a table or a whole database.

How are the relationships worked out?

From the foreign keys. A table with a foreign key is drawn as the "many" side of a relationship to the table it references. If the foreign key column is also unique or the primary key, it becomes one-to-one, and if it can be NULL, the parent side becomes optional.

Why do some types look different?

Mermaid's ER syntax cannot have spaces or commas in a column type, so "timestamp with time zone" becomes timestamp_with_time_zone and numeric(10, 2) becomes numeric(10_2). Column and table names keep letters, digits, underscores and hyphens.

Is my schema sent anywhere?

No. The SQL is parsed in your browser and is not uploaded or stored.

More Mermaid tools

All tools