ERD Generator
Generate ER diagram code from SQL DDL — export as Mermaid.js, PlantUML, or Graphviz DOT
Generated ERD Code
erDiagram
USERS ||--o{ ORDERS : "has"
USERS {
int id PK
string name
}
Tables
0
Relationships
0
Format
-
Lines
0
What Is an ER Diagram?
An Entity-Relationship Diagram (ERD) is a visual representation of database tables and their relationships. It shows entities as boxes, attributes as fields, and relationships as lines connecting foreign keys. Generated code can be used with Mermaid.js (renders in GitHub Markdown), PlantUML, or Graphviz.
How to Use This Tool
- Paste your SQL DDL — Enter one or more CREATE TABLE statements with primary and foreign keys.
- Select output format — Choose Mermaid.js ERD, PlantUML, or Graphviz DOT format.
- Click Generate — The tool parses your DDL and generates ERD code in the selected format.
- Copy or download — Click Copy to grab the code, or Download to save the file for use in documentation.
- Embed in your project — Paste Mermaid ERD into GitHub Markdown, PlantUML into documentation, or DOT into Graphviz tools for rendering.
Create an ER Diagram from SQL
The fastest way to draw an ER diagram is to start from the schema you already have. Paste the CREATE TABLE statements from a migration, a dump, or a design document, then choose an output format.
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) NOT NULL UNIQUE
);
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
total DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE order_items (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT NOT NULL,
quantity INT NOT NULL DEFAULT 1,
FOREIGN KEY (order_id) REFERENCES orders(id)
);
For this schema the tool reads three tables, marks id as the primary key, links user_id and order_id to their parent tables, and normalizes types to int, float, boolean, datetime, or string. Defaults, indexes, and constraints do not appear in the diagram — the goal is the shape of the schema, not a full DDL dump.
Mermaid ER Diagram Syntax
Mermaid is the most portable output because GitHub, GitLab, and many Markdown editors render it natively. The generated code looks like this:
erDiagram
USERS {
int id PK
string name
string email
}
ORDERS {
int id PK
int user_id FK
float total
datetime created_at
}
USERS ||--o{ ORDERS : "ref"
ORDERS ||--o{ ORDER_ITEMS : "ref"
Read the relationship line from left to right: ||--o{ means exactly one record on the left can have zero or more on the right. The label after the colon is free text; the generator writes ref, but places, contains, or belongs to reads better in documentation. To render the block, paste it into a fenced code block tagged mermaid, or open mermaid.live for a quick preview.
What the Parser Supports
The generator uses a focused DDL parser, not a database engine. Knowing the boundary saves time when a table or relationship does not show up.
| Read | Not read |
|---|---|
CREATE TABLE and IF NOT EXISTS | ALTER TABLE and constraints added later |
Backticks and schema-qualified names such as public.users | Views, triggers, and stored procedures |
Table-level PRIMARY KEY (a, b) and FOREIGN KEY ... REFERENCES | Column-level REFERENCES clauses |
Columns named user_id / userId when a matching table exists | INDEX, KEY, UNIQUE, CONSTRAINT, FULLTEXT, SPATIAL |
| Type names, normalized to five display types | Defaults, checks, collations, and exact type lengths |
If a relationship is missing, the usual cause is an inline REFERENCES or a foreign-key column that does not follow the *_id pattern. Add a table-level FOREIGN KEY (column) REFERENCES table(id) line inside the CREATE TABLE block and generate again.
Frequently Asked Questions
What is the difference between this and the DB Schema Visualizer?
The DB Schema Visualizer renders an interactive graphical diagram in your browser. This ERD Generator produces code in Mermaid, PlantUML, or DOT format that you can embed in Markdown, wikis, or documentation tools.
Which SQL dialects are supported?
The parser reads CREATE TABLE statements from MySQL, MariaDB, PostgreSQL, and SQLite dumps. It understands table-level PRIMARY KEY and FOREIGN KEY clauses, backticked or schema-qualified names, and common column types, which are normalized for display. ALTER TABLE, views, and triggers are not read.
Can I use Mermaid output in GitHub Markdown?
Yes. GitHub natively renders Mermaid.js ERD diagrams in Markdown files. Simply paste the generated Mermaid code into a code block with the mermaid language tag.
Is my schema data sent to a server?
No. All parsing and code generation happens locally in your browser. Your SQL schema never leaves your device.
How do I render PlantUML or DOT output?
PlantUML requires a PlantUML server or the PlantUML plugin for your IDE. Graphviz DOT can be rendered using the dot command-line tool or online Graphviz viewers.
Why is a column or relationship missing?
Check three things: the table must be declared with CREATE TABLE, foreign keys must be table-level FOREIGN KEY ... REFERENCES clauses (inline REFERENCES and ALTER TABLE are not read), and inferred links only work for columns named like user_id or userId when a matching table exists.
Can I export the diagram as PNG or SVG?
Not directly. The tool downloads text files: .mmd for Mermaid, .puml for PlantUML, and .gv for Graphviz. Render the file in mermaid.live, a PlantUML server, or the dot command, then export the image from that renderer.
Does it work with mysqldump output?
Yes, as long as the dump contains CREATE TABLE statements. INSERT statements, locks, and comments are ignored because the parser only looks for table definitions. Very large dumps may be slow to paste, so extract the CREATE TABLE blocks first.