SQL ER diagram generator
Einfügen CREATE TABLE statements and get an ER diagram you can rearrange, restyle
and export as SVG, PNG, Mermaid or DBML.
It runs in your browser, and your schema never leaves it.
Paste CREATE TABLE statements into the editor. The diagram draws as you type.
Drag tables or the background · Ctrl + scroll to zoom · arrow keys pan · Help lists every shortcut Tap the diagram, then drag with one finger and pinch with two · Help lists the rest
The diagram as text
Privat. The parser and renderer run in this tab and nothing is uploaded. What is stored, and how share links stay private
What an ER diagram shows
An entity-relationship diagram is a picture of a database schema. Each table becomes a box that lists its columns with their data types; primary-key and foreign-key columns carry badges so you can spot the keys without reading the SQL. A line between two tables means one holds a foreign key into the other. The markers at each end tell you which side is the one and which is the many, which is the cardinality your JOIN will produce.
The diagram is built only from what the DDL declares. A composite key shows up on every
column in its list, ON DELETE CASCADE is printed on the line it belongs to, and a table that
is referenced but not in the paste is drawn as a dashed placeholder. Nothing is inferred
from column names: a customer_id column with no foreign key gets no line, which
is often the first thing worth knowing about a schema.
- Boxes are tables. Each column is listed with its type. PK, FK and UQ badges mark the key columns, and IX marks a column that leads an index. The options panel can hide types, mark nullable or NOT NULL columns, show defaults and comments, list each table's keys by name, or cut a box down to its key columns or its name alone.
- Lines are foreign keys. Each relationship is drawn from the referencing column to the referenced one, with its ON DELETE and ON UPDATE actions when they are anything other than NO ACTION, and optionally the constraint's name. A self-reference (an employee's manager_id) loops back into its own box.
- The ends show cardinality. In crow's foot notation the parent end is a double bar (exactly one) when every foreign-key column is NOT NULL, and a bar and circle (zero or one) when a column can be NULL. The child end is a crow's foot (zero or more), or zero or one when the foreign-key columns are also the child's primary key or a unique key. UML labels (1, 0..1, 0..*) and plain 1/n labels show the same facts.
- Layout is automatic. Tables that reference no other table go in the first column (or row, top to bottom), every other table goes after the tables its foreign keys point to, and tables with no relationships are gridded at the end. Drag any box and the lines reroute. Your positions, options and DDL are kept in this browser.
- Export as an image or as code. SVG for docs and drawing tools, PNG at 2x or 4x for chats and tickets, both in your current light or dark theme. Mermaid and DBML exports turn the schema into diagram code for GitHub, docs sites or dbdiagram.io, with your key names in place.
DDL features the parser understands
The parser reads the CREATE TABLE und ALTER TABLE ... ADD syntax of
SQL Server, PostgreSQL, MySQL and SQLite, including the output of pg_dump,
mysqldump and SQL Server's Generate Scripts. Anything it cannot parse is reported
with its line number; everything else still gets diagrammed.
| Funktion | Beispiel | How it is drawn |
|---|---|---|
| Quoted identifiers | "order", `order`, [order] | Unquoted and matched case-insensitively across the schema |
| Inline column constraints | id INTEGER PRIMARY KEY | PK badge on the column |
| Named table constraints | CONSTRAINT fk_x FOREIGN KEY … | Same relationship as the inline REFERENCES form |
| Keys added after the table | ALTER TABLE ONLY orders ADD CONSTRAINT … FOREIGN KEY | Merged into the table wherever the ALTER appears in the script; also ADD PRIMARY KEY, ADD UNIQUE, ADD COLUMN, and column changes such as PostgreSQL ALTER COLUMN … SET NOT NULL and MySQL MODIFY |
| Composite keys | PRIMARY KEY (order_id, product_id) | PK badge on every column of the list; one relationship line per foreign key |
| UNIQUE constraints | UNIQUE (email), column-level UNIQUE, MySQL UNIQUE KEY uq (email) | UQ badge on the constrained columns |
| Constraint names | CONSTRAINT pk_orders PRIMARY KEY, CONSTRAINT fk_x REFERENCES | Shown in the key list, tooltips and on lines. Unnamed keys can show the names PostgreSQL or MySQL would generate, and any name can be overridden |
| Indizes | CREATE [UNIQUE] INDEX ix ON t (a, lower(b)), MySQL KEY ix (a) | IX badge on the leading column and listed in the table's key list; a unique index also counts as a unique key |
| Kommentare & Codefaltung | MySQL COMMENT 'text', COMMENT ON TABLE / COLUMN … IS, SQL Server sp_addextendedproperty 'MS_Description' | Under the column or table name, or in the tooltip only |
| Nullbarkeit | NOT NULL, NULL, primary keys, identity columns | Columns without NOT NULL are nullable. Primary-key columns and identity columns (IDENTITY, GENERATED AS IDENTITY, serial, AUTO_INCREMENT) count as NOT NULL, as their engines enforce. In SQLite, primary-key columns accept NULL unless the column is INTEGER PRIMARY KEY or the table is STRICT or WITHOUT ROWID |
| Referential actions | ON DELETE CASCADE / SET NULL / RESTRICT | Labelled on the relationship line; also ON UPDATE |
| Column defaults | DEFAULT CURRENT_TIMESTAMP, DEFAULT 'new', SQL Server ADD DEFAULT 0 FOR qty | Shown exactly as written when Standardeinstellungen ist eingeschaltet |
| Schemas in names | CREATE TABLE sales.orders … | REFERENCES orders findet sales.orders when only one table has that name |
| Identity and computed columns | GENERATED ALWAYS AS IDENTITY, IDENTITY(1,1), AS (qty * price) | Eine auto marker on identity columns; computed expressions shown with the defaults |
| Skripte mit mehreren Anweisungen | CREATE TABLE …;, SQL Server GO batches, MySQL DELIMITER ;; | Every statement parsed on its own, so one error never blocks the rest. Function bodies in $$ quotes and procedure bodies under DELIMITER are skipped whole |
| Ignored by design | CHECK, ENGINE=, SET, CREATE VIEW | Skipped, since they do not change the entity picture; skipped statements are counted in the status line |
ER diagram generator FAQ
What is an ER diagram?
An entity-relationship (ER) diagram is a picture of a database schema. Each table is drawn as a box listing its columns, with lines between tables that reference each other through foreign keys. It shows at a glance which table owns which data and how the tables join.
Which databases does the DDL parser support?
SQL Server, PostgreSQL, MySQL and MariaDB, and SQLite. You do not pick a dialect: the parser accepts [brackets], "double quotes", `backticks` and unquoted names in the same script, and it reads the dump formats of pg_dump, mysqldump and SQL Server's Generate Scripts, which declare many keys in ALTER TABLE statements after the tables.
Is my schema sent to a server?
No. The parser and the renderer are this page's own JavaScript, with no CDN libraries, and they run in your browser tab. Your DDL is never uploaded or logged. The DDL, options and layout are saved in this browser's local storage so they are there next time; Start over clears them. A share link carries the diagram after the # in the URL, the part browsers never send to a server, so only the people you give the link to can open it. Once the page has loaded it keeps working offline.
Can I choose what each table shows?
Yes. The options panel decides whether boxes list every column, only key columns, keys plus NOT NULL columns, or just the table name. You can switch data types, nullability markers, defaults, identity markers, column and table comments, schema names and key badges on or off, change the badge labels, and collapse or hide single tables. Pick crow's foot, UML or 1/n notation and right-angle, curved or straight lines.
Can I rename keys and constraints?
Yes. The Key names tab lists every primary key, foreign key, unique constraint and index with the name from the DDL. Type a new name to override it in the key lists, on relationship lines, in tooltips and in the Mermaid and DBML exports. Keys the DDL left unnamed can show the names PostgreSQL or MySQL would generate (orders_pkey, orders_customer_id_fkey or PRIMARY, orders_ibfk_1), or pk_/fk_/uq_/ix_ convention names.
What DDL can the parser read?
CREATE TABLE statements with quoted identifiers, inline column constraints and named CONSTRAINT clauses, single and composite primary keys, UNIQUE constraints, foreign keys with ON DELETE and ON UPDATE actions, and schema-qualified names. ALTER TABLE ... ADD CONSTRAINT and ADD COLUMN are merged into their table. CREATE TABLE ... AS SELECT is reported as unsupported, because it has no column list to read.
Can I arrange the tables myself?
Yes. Drag any table box and its relationship lines follow it. From the keyboard, Tab to a table, press Enter to select it, and the arrow keys nudge it. Drag the background to pan, and use Ctrl or Cmd with the scroll wheel, or pinch, to zoom. On a touch screen, tap the diagram first so a swipe moves the diagram instead of the page. Tidy layout returns everything to the automatic placement, left to right or top to bottom, which puts each table after the tables it references.
How do I export the diagram?
Download SVG gives a vector file you can open in a drawing tool or embed in documentation, and Download PNG gives a bitmap at two or four times the diagram's natural size. Both are rendered from the diagram you see, with your options and dragged boxes, in your current light or dark theme. Mermaid and DBML exports give the visible tables as diagram code you can paste into GitHub Markdown or dbdiagram.io.
What happens if my DDL has errors?
Statements that fail to parse are listed under the editor with their line number, and clicking one selects that line. Everything that did parse is still diagrammed. A missing closing parenthesis is reported at the next semicolon, so one broken table does not cost you the rest of the diagram.
Related on SQLly
- SQL schema design & normalization interview questions Interview questions
- Add a foreign key or check constraint Dialect comparison
- Add a foreign key if it does not exist Snippet
- Distribution of foreign-key values Snippet
- List foreign keys and the tables/columns they point at Snippet
- Find foreign keys without a supporting index in PostgreSQL Snippet
Like the diagram? Meet the rest of SQLly
A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and a table explorer that covers every connection.