Tools / SQL / DBML to ER Diagram

SQL / DBML to ER Diagram.

Draw an entity-relationship diagram from CREATE TABLE statements or DBML and download it as SVG.

Runs in your browser
Diagram

Paste a schema or load the example to draw the diagram.

Relations

    About SQL / DBML to ER Diagram

    This tool draws an entity-relationship diagram from the schema you already have. Paste CREATE TABLE statements from a MySQL, PostgreSQL or SQLite dump, or DBML as used by dbdiagram.io, and the diagram appears next to the editor as you type. Each table becomes a box with its columns and types, primary keys are marked PK, foreign keys FK, and nullable columns carry a question mark after the type. Relations come from FOREIGN KEY and REFERENCES clauses, ALTER TABLE … ADD FOREIGN KEY statements, DBML Ref lines and inline ref settings, and are drawn as curves with crow's-foot ends, so you can see at a glance which side is "many". A foreign key on a unique or primary-key column is drawn as one-to-one, and DBML's <> operator as many-to-many. Tables with the most relations are placed first so that the busiest part of the schema stays in the top-left corner. The finished diagram downloads as a standalone SVG that scales without blurring in documentation, pull requests or slides, and the tables and relations are also listed as text below it. For example, a posts table with user_id integer [ref: > users.id] produces a line from posts.user_id to users.id with the many end at posts. Common reasons for a missing line are a foreign key pointing at a table that is not in the pasted schema, or a relation that only exists in application code. The schema never leaves your browser.

    How to Use

    1. Paste CREATE TABLE statements or DBML; the format is detected automatically.
    2. Check the diagram and the relations list for missing foreign keys.
    3. Download the SVG or copy its markup into your documentation.

    Frequently Asked Questions

    Which input formats are supported?

    SQL CREATE TABLE statements in MySQL, PostgreSQL and SQLite syntax, including ALTER TABLE … ADD FOREIGN KEY, and DBML with Table blocks, column settings such as pk and not null, inline ref settings and Ref statements. DBML enums, notes and table groups are skipped.

    Can I move the tables around?

    Not yet. Tables are placed on a grid automatically, with the most connected ones first. Edit the SVG in a vector editor if you need a custom layout.

    Why is a relation missing?

    The referenced table must be part of the pasted schema, and the relation must be declared with FOREIGN KEY, REFERENCES or a DBML ref. Relations that exist only in code cannot be detected.

    Is my schema uploaded?

    No. Parsing and drawing happen in your browser.

    Related Tools