Guide
Drawing entity-relationship diagrams from a SQL schema
An entity-relationship diagram shows the tables of a database as boxes and their foreign keys as lines. It is the quickest way to explain a schema to a new developer, check a design before building it, or document a database for a course or a client. Drawing one by hand in a diagram editor takes time and goes out of date the moment the schema changes. This tool draws it straight from the SQL.
From SQL to a diagram
Paste CREATE TABLE statements in PostgreSQL, MySQL or SQLite syntax. Each table becomes an entity box listing its columns with their types. Primary key columns are marked PK, foreign keys FK and unique columns UK. Every foreign-key column, whether declared inline with REFERENCES or in a separate FOREIGN KEY constraint, becomes a line from the referenced table to the table that holds the key, labelled with the column name.
How cardinality is chosen
The ends of each line use crow’s-foot notation, and the tool reads the constraints to decide which symbols apply. A foreign key that is also UNIQUE means each parent row can have at most one child, so the relationship is drawn as one to zero-or-one. A nullable foreign key means a child may exist without a parent, drawn as zero-or-one to many. A NOT NULL foreign key without uniqueness is the classic one-to-many, drawn as exactly one parent to zero or more children.
The Mermaid source
Behind every drawing is Mermaid erDiagram text, which is shown under the diagram. You can copy it into documentation that renders Mermaid, such as GitHub, GitLab, Notion or Obsidian, or switch to Mermaid mode and write or edit the text yourself, for example to add relationship labels like “places” or “contains”, or to sketch a design before any SQL exists.
A worked example
The Sample schema has four tables: users, products, orders and order_items. The generated source contains three relationships: users ||--o{ orders : "user_id", orders ||--o{ order_items : "order_id" and products ||--o{ order_items : "product_id". In the drawing, order_items shows both of its key columns marked PK and FK, because together they form its composite primary key. The PNG export of this diagram is about 170 KB.
Exporting
The SVG download is a vector file that stays sharp at any size and can be edited in Figma, Inkscape or Illustrator. The PNG is rendered at twice the on-screen size on a background that matches the current light or dark theme, which suits slides, tickets and chat messages. The zoom buttons only change the view, not the exported files.
When a generated diagram is not enough
The layout is computed automatically, so boxes cannot be dragged into position. For schemas with dozens of tables, split the SQL by area, such as billing or accounts, and draw each part separately; one huge diagram is hard to read anyway. Many-to-many relationships appear as two one-to-many lines through the join table, which is accurate for the database even if a conceptual model would draw a single line.
Reviewing a schema with the diagram
A diagram makes some design problems obvious: a table with no relationships at all, two tables that reference each other in a loop, or a foreign key drawn as zero-or-one where the business rule says every order must have a customer, which means the column should be NOT NULL.
Related tools
- SQL to Prisma turns the same tables into a Prisma schema.
- Mermaid Diagram Editor handles flowcharts, sequences and other diagram types.
- Graphviz Viewer renders DOT graphs from other tools.
- SQL Formatter cleans up the input statements.
Checked against the current version of the ER Diagram Maker on .

