Start a project

Tool 138 of 194 · Databases

SQL Schema to ER Diagram

Turn CREATE TABLE statements or a schema dump into an entity relationship diagram with the right cardinality, and catch foreign keys that have no index or mismatched types.

SQL Schema to ER Diagram at a glanceIllustration: 1, CREATE TABLE; 2, processed in your browser; 3, ER diagram.SQL Schema to ER Diagram</>1CREATE TABLE3ER diagram2In yourbrowser
1 CREATE TABLE 2 processed on your device 3 ER diagram

SQL Schema to ER Diagram

Your schema

ER diagram

  • Crow's foot: many rows on this side
  • Bar: exactly one
  • Dashed line and circle: optional (the foreign key can be null)

    Mermaid

    Mermaid erDiagram

    DBML

    DBML (dbdiagram.io)

    Skipped statements

    LineWhyStatement

    Columns per table

    01

    What it does

    Draws an entity relationship diagram from CREATE TABLE and ALTER TABLE statements, flags foreign keys with no index and exports Mermaid and DBML.

    • PostgreSQL, MySQL and SQLite DDL, including pg_dump and mysqldump output
    • Foreign keys inline, as table constraints and from ALTER TABLE
    • One-to-one, one-to-many and optional relations read from UNIQUE and NULL
    • Foreign keys with no index, type mismatches and tables with no primary key flagged

    02

    Private by design

    Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

    03

    What you get

    An SVG or PNG diagram, schema checks, Mermaid and DBML, with a Copy and a Download button on every result.

    • SQL
    • ER diagram
    • PostgreSQL
    • MySQL

    Why it matters

    Schemas live in migration files and dump output, and reading forty CREATE TABLE statements to work out how the tables join is slow. Diagram tools usually want you to redraw the schema by hand or connect them to the database.

    This tool reads the DDL itself. It splits the script into statements (respecting quotes, comments and function bodies), reads columns, primary keys, unique constraints and foreign keys wherever they're declared, including ALTER TABLE ... ADD CONSTRAINT lines from pg_dump, and works out each relation's cardinality: a unique foreign key is one-to-one, a nullable one is optional. It then lays the tables out, draws crow's-foot connectors and checks the schema for problems a review would catch: foreign keys with no index on the referencing columns (slow joins and slow deletes on the parent), a foreign key column whose type doesn't match the key it points at, and tables without a primary key. Nothing is sent anywhere.

    How it works

    1. InputCREATE TABLE statements or a schema dump
    2. In your browserTables, keys and cardinality read from the DDL
    3. OutputA diagram, schema checks, Mermaid and DBML

    Where it fits in a designer's workflow

    1. Plan
    2. Design
    3. Build
    4. Test
    5. Launch
    Understanding or documenting a database before you change it.

    By the numbers

    Columns per table in the sample schemaaddresses: 5 columns, 1 foreign key; product_variants: 5 columns, 1 foreign key; orders: 5 columns, 2 foreign keys; reviews: 5 columns, 2 foreign keys; customers: 4 columns, 0 foreign keys; products: 4 columns, 0 foreign keys; order_items: 4 columns, 2 foreign keys; payments: 4 columns, 1 foreign keyaddresses5 columns, 1 foreign keyproduct_variants5 columns, 1 foreign keyorders5 columns, 2 foreign keysreviews5 columns, 2 foreign keyscustomers4 columns, 0 foreign keysproducts4 columns, 0 foreign keysorder_items4 columns, 2 foreign keyspayments4 columns, 1 foreign key
    Read by this tool from its sample pg_dump: 8 tables, 36 columns and 9 relationships, with 5 schema checks raised and 6 statements skipped (settings, ownership, comments and a function). Foreign keys are counted on the table that holds them. Source: PostgreSQL: CREATE TABLE; PostgreSQL: foreign keys and indexes.
    Show the numbers as a table
    TableColumnsForeign keys
    customers40
    addresses51
    products40
    product_variants51
    orders52
    order_items42
    payments41
    reviews52

    How to use it

    1. Paste your CREATE TABLE statements, or the output of pg_dump --schema-only, mysqldump -d or sqlite3 .schema.
    2. Read the diagram; click a table name in the list to centre it.
    3. Work through the schema checks.
    4. Download the diagram, or copy the Mermaid or DBML into your docs.

    FAQ

    Which databases does it understand?

    PostgreSQL, MySQL and MariaDB, and SQLite DDL. It detects the dialect from the syntax, such as bigserial, AUTO_INCREMENT or backtick quoting. Statements it doesn't model, like functions, grants and comments, are listed as skipped.

    How is one-to-one decided?

    A foreign key whose columns are also a primary key or have a UNIQUE constraint can only match one row per parent, so it's drawn one-to-one. A nullable foreign key is drawn as optional.

    Why does it want an index on foreign keys?

    PostgreSQL doesn't create one automatically. Without it, joins from the child side scan the table, and deleting or updating a parent row has to scan the child table to check the constraint. MySQL InnoDB creates one for you.

    Can I use the Mermaid output on GitHub?

    Yes. Paste it into a ```mermaid code block in a README or issue and GitHub draws it.

    Is my schema uploaded?

    No. It's parsed and drawn in your browser.

    Work with me

    Want a site that gets these right?

    I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

    All developer tools · Back to leej.uk