N
NJHTools

SQL to ER Diagram Generator

Paste your CREATE TABLE statements and get an ER diagram with tables, keys and crow's foot relationship lines in seconds. It reads PostgreSQL, MySQL and SQL Server, lays the tables out automatically, and runs entirely in your browser.

PostgreSQL codeYour schema stays in this browser.

Tab indents. Press Esc, then Tab, to move focus out. Autosaved in this browser.

How to generate an ER diagram from SQL

  1. 1Pick the dialect your SQL was written for: PostgreSQL, MySQL or SQL Server.
  2. 2Paste the CREATE TABLE statements or a schema-only dump into the editor.
  3. 3Review the diagram: foreign keys become lines between the related tables.
  4. 4Drag tables to adjust the layout, or re-run auto-layout.
  5. 5Export the diagram as PNG or SVG, or convert the SQL to DBML or a Mermaid erDiagram.

What the diagram reads from your SQL

Every CREATE TABLE becomes a box listing its columns and types. PRIMARY KEY, NOT NULL and UNIQUE constraints are shown as markers on the columns, and enum types become their own boxes.

Relationship lines come only from declared foreign keys: an inline REFERENCES clause, a FOREIGN KEY constraint in the table, or a later ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY, which is how most dump tools write them. A column named user_id without a foreign key constraint is just a column, so if lines are missing, check that the keys are actually declared.

Getting a schema-only dump

You only need the structure, not the data. PostgreSQL: pg_dump --schema-only --no-owner --no-privileges mydb > schema.sql (add -n myschema to limit it to one schema). MySQL and MariaDB: mysqldump --no-data --skip-triggers mydb > schema.sql. SQL Server: in SSMS, right-click the database, choose Tasks > Generate Scripts, pick the tables, and under Advanced set Types of data to script to Schema only.

Dumps can include functions, triggers, views, sequences and grants. If one of those stops the parser, delete it; the diagram needs only the table definitions and the statements that add primary and foreign keys.

Crow's foot notation explained

Each relationship line connects a foreign key column to the key it points at. The end of the line shows how many rows can sit on that side: a single bar means one, and the three-pronged crow's foot means many. A line from posts.user_id to users.id with the crow's foot at posts reads as "one user has many posts, each post belongs to one user".

In full crow's foot notation a circle next to the end means zero is allowed (optional) and a second bar means at least one is required (mandatory). In SQL terms, a nullable foreign key column is the optional case and a NOT NULL foreign key is the mandatory one, so check the NOT NULL markers on the column when you need to know whether a row can exist without its parent.

One-to-one relationships have a bar at both ends and usually come from a foreign key that is also UNIQUE or the primary key. Many-to-many relationships cannot be stored directly in a relational database; they need a junction table, such as post_tags with post_id and tag_id, which turns them into two one-to-many lines.

Frequently Asked Questions

Is my database schema private? Is anything uploaded?↓

Nothing is uploaded. Parsing, layout and every export run in your browser, and the diagram is autosaved only in this browser's local storage. There are no share links on purpose, because table and column names can reveal how a product works. No signup is needed.

Which SQL dialects can I paste?↓

PostgreSQL, MySQL (including most MariaDB schemas) and SQL Server (T-SQL). Choose the matching dialect before pasting, because each one quotes names and declares types and auto-increment columns differently. Oracle is available as an export target, not as input.

How do I get the schema of my existing database?↓

Export a schema-only dump and paste it in. PostgreSQL: pg_dump --schema-only --no-owner mydb > schema.sql. MySQL: mysqldump --no-data mydb > schema.sql. SQL Server: in SSMS, right-click the database, choose Tasks > Generate Scripts, and under Advanced set Types of data to script to Schema only. The tool does not connect to databases itself.

Why are some relationship lines missing?↓

Lines are drawn only for declared foreign keys. Tables created without FOREIGN KEY or REFERENCES constraints, which is common with MySQL MyISAM tables or with ORMs that skip constraints, have no lines to draw. Add the constraints to the SQL, or switch to DBML and add Ref lines by hand.

Which export formats are available?↓

You can export CREATE TABLE SQL for PostgreSQL, MySQL, SQL Server or Oracle, the schema as DBML, a Mermaid erDiagram for Markdown docs on GitHub or GitLab, and the diagram itself as a PNG image or an SVG vector file. Convert SQL to DBML turns pasted SQL into DBML you can keep editing.

All Text & Dev Tools →

Last updated: