SQL to ER Diagram
Paste CREATE TABLE statements to get an ER diagram whose tables you can move yourself. Lines are drawn from foreign keys, route around other tables, and use crow's foot notation, which shows the direction of one-to-many relations. It also reads the output of pg_dump or SHOW CREATE TABLE and foreign and primary keys added with ALTER TABLE, so you can grasp the overall shape of an unfamiliar database quickly. Group related tables together to make a diagram for a design review, then export as PNG, SVG, DDL or Mermaid to paste into a README or design doc. You can also save as JSON and load it again to update when the schema changes. Partitions, views and similar are skipped. Everything runs in your browser; your SQL is never uploaded.
Drag to move · Arrow keys to nudge · Delete to remove · Ctrl+Z to undo. Click a table to edit its columns and relations in the panel below
The tables and their positions are saved automatically in this browser (nothing is sent to a server).
Export & save
ER Diagram (Mermaid)
Import from DBML (dbdiagram.io)
Paste DBML (the notation used by dbdiagram.io): Table, columns with [pk, increment, not null, unique, default, ref], indexes blocks and Ref lines. It is converted to CREATE TABLE for the database you choose, put in the SQL box above, and drawn as an ER diagram you can edit. Enum, TableGroup and notes are ignored.
Skipped
Compare two schemas (migration SQL)
Paste the old and the new CREATE TABLE statements to get the ALTER TABLE statements that turn one into the other. It only compares the definitions; it never sees your data. Read every statement before you run it.
Review the schema, indexes and sample data
Works on the CREATE TABLE statements in the box above. Find design problems, get CREATE INDEX statements for foreign keys, or generate sample INSERT statements that respect foreign keys. It reads the SQL only; no database is touched.
Export as TypeScript, Prisma, JSON Schema or Zod
Reads the generated CREATE TABLE statements above and writes the same tables as code. Decimals and uuids become strings, dates stay ISO strings unless you choose Date.
No CREATE TABLE statements yet. Create tables above first.
GuideHow to use & features
- Paste CREATE TABLE statements and press "Draw ER diagram" to lay out the tables and their foreign-key lines automatically. "Load sample" lets you try it first.
- Drag tables to move them. Use arrow keys to nudge, Delete to remove, and Ctrl+Z / Ctrl+Y (⌘ on Mac) to undo and redo.
- Click a table to edit its name, columns (name, type, PK, NOT NULL, UNIQUE) and relation lines in the panel below.
- "Add table" creates a new table and "Add relation" draws a foreign-key line. Lines route around other tables automatically.
- The "Mermaid" tab lets you copy the Mermaid code and save an image. You can also export PNG, SVG or JSON, copy CREATE TABLE statements, and continue to "Build query from this schema".
SamplesExamples
Users and Posts (One-to-Many)
CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(50) ); CREATE TABLE posts ( id INT PRIMARY KEY, user_id INT REFERENCES users(id), title VARCHAR(100) );
erDiagram
users {
INT id PK
VARCHAR(50) name
}
posts {
INT id PK
INT user_id
VARCHAR(100) title
}
posts }|--|| users : "user_id -> id"FAQFAQ
How do I generate an ER diagram from SQL?
Paste your CREATE TABLE statements (or click Load sample), then click Draw ER diagram. The tables appear with lines drawn from the foreign keys. Drag the tables into a layout you like, or use Auto-arrange, then export PNG, SVG or JSON from Export & save.Can I convert SQL to a Mermaid ER diagram?
Yes. Switch to the Mermaid tab to get the erDiagram code and copy it with Copy Mermaid Code. Mermaid does not store table positions, so the layout is decided when Mermaid renders it. If you want to arrange the tables yourself, use the editable diagram and export PNG or SVG instead.How do I make an ER diagram from an existing database?
Export the schema as SQL and paste it here: pg_dump --schema-only for PostgreSQL, mysqldump --no-data for MySQL, or SHOW CREATE TABLE for individual MySQL tables. Everything is processed in your browser, so the schema is not uploaded.Can I edit the diagram after it is drawn?
Yes. Click a table to edit its columns and relationships in the panel below, add new tables, and move them by dragging. Undo and redo are available, and your edits are saved in this browser automatically.Which SQL can I load?
You can load `CREATE TABLE` statements for MySQL, PostgreSQL, SQLite and similar. `ALTER TABLE ... ADD FOREIGN KEY` / `ADD PRIMARY KEY` as written by pg_dump is supported too. Relation lines are drawn from foreign keys and types are shown as written. Unsupported syntax (partitioning, for example) is skipped, so check the SQL if a table does not appear.What do the symbols at the line ends mean?
This is crow's foot notation. The foreign key side (child) gets a three-pronged foot meaning "many", and the referenced side (parent) gets a double bar meaning "one". A circle on the foot means the foreign key column allows NULL, so "zero or more". With a NOT NULL column there is no circle and it reads "one or more". When the foreign key is a primary key or UNIQUE, it is drawn as one-to-one.Is my diagram saved? How can I export it?
Your edits are saved automatically in this browser's local storage (nothing is sent to a server). Clearing the cache erases them, so use "Save as JSON" for diagrams you care about. You can export PNG / SVG / JSON and copy CREATE TABLE statements and Mermaid. Mermaid does not include position information.Is my SQL sent to a server?
No. Loading, drawing and exporting all happen in your browser, so you can paste internal schemas safely.What if relationships are not showing up?
Ensure that your statements include FOREIGN KEY or REFERENCES clauses. The tool relies on these constraints to identify and draw relationships.Can it generate ALTER TABLE from the difference between two schemas?
Yes, but it only compares definitions, so it cannot judge what happens to your data. Dropping a column or table is marked "data is lost", and adding NOT NULL without a DEFAULT or changing a type is marked "check before running". A column that was only renamed shows up as a drop plus an add, so it warns about pairs that may be renames. Always read the statements before running them.
Use casesCommon use cases
ER diagrams for design reviews
Because you decide where each table sits, you can group related tables together and make a diagram that is easy to explain in a review.Understanding an existing database from a dump
Paste the output of pg_dump or SHOW CREATE TABLE and the foreign-key relations become a single picture, so you can grasp an unfamiliar schema quickly.Diagrams for READMEs and design docs
Export as PNG / SVG and paste. Save as JSON so you can load and fix it when the schema changes.Explaining the data model to new teammates
Crow's foot notation makes the direction of "one-to-many" clear, so the diagram works as-is for explaining the data model.
NotesNotes & limitations
Some syntax cannot be loaded
Loading covers `CREATE TABLE` and `ALTER TABLE` for foreign and primary keys. Partitioning, vendor-specific extensions and views are skipped. If a table does not appear, try the SQL cut down to just that part.Exported DDL is for reference
Types are output as entered and not converted between dialects. Indexes, CHECK constraints, defaults and character sets are not included. Review it before using it for production migrations.Lines can overlap other lines
Lines route around other tables, but lines can overlap or cross each other. Moving the tables lets you tidy the layout.
AboutAbout this tool
About the SQL to ER Diagram (Mermaid) Generator
This online tool automatically generates Entity-Relationship (ER) diagrams in Mermaid.js format directly from your SQL DDL statements (CREATE TABLE).
Visualizing schemas directly from your database definitions dramatically improves efficiency during database design reviews and documentation creation.
How It Works & Privacy
This tool runs entirely in your browser using JavaScript. The SQL statements you input, including table structures and foreign key relationships, are never transmitted to any external servers.
You can safely use it to visualize the most sensitive internal database schemas without any risk of information exposure.
Articles for this tool
Generate ER Diagrams from SQL DDL: How CREATE TABLE Parsing Works
How the SQL to ER diagram tool parses CREATE TABLE DDL into a Mermaid ER diagram: PRIMARY KEY/FOREIGN KEY extraction, column types, and unsupported patterns.
How CREATE TABLE Generation From a Visual Table Design Works | DDL Builder
How DDL Builder turns a visual table design into CREATE TABLE statements and an ER diagram: MySQL/PostgreSQL/SQLite type mapping and JSON column inference.
SQL Clause Order Reference: Why WHERE Can't See Your SELECT Alias
SQL is written in one order and run in another. The logical execution order (FROM to LIMIT), why aliases fail in WHERE, and WHERE vs HAVING.
CREATE TABLE Reference: MySQL vs PostgreSQL vs SQLite Types & Constraints
Cross-database CREATE TABLE reference: data types, auto-increment (AUTO_INCREMENT / IDENTITY / rowid), ON DELETE, and the CHECK that MySQL silently ignores.
Mermaid ER Diagram Syntax Reference: Relationship Symbols & Real Examples
Reference for Mermaid erDiagram syntax: crow's foot cardinality cheat sheet, one-to-many vs many-to-many, PK/FK attributes, and a full e-commerce example.
