CREATE TABLE → Mermaid ER
Convert CREATE TABLE statements into a Mermaid erDiagram.
Overview
The CREATE TABLE to Mermaid converter reads SQL DDL and emits a Mermaid erDiagram block you can paste into a README, design doc, or wiki page. Each table becomes a node listing its columns and types, with foreign keys drawn as relationship lines between entities.
It's the fastest way to bootstrap an entity relationship diagram from an existing schema without firing up dbdiagram, DrawSQL, or a full ER modeling tool. Backend developers, database architects, and tech writers use a sql to mermaid converter when documenting an application database or onboarding new teammates.
How it works
The parser walks CREATE TABLE statements, extracts column names and types, and identifies primary and foreign keys from both inline constraints (REFERENCES other(id)) and table-level FOREIGN KEY clauses. Both MySQL, PostgreSQL, and SQL Server flavours of DDL are recognised — the parser is forgiving about backticks, brackets, and IF NOT EXISTS.
Mermaid's erDiagram syntax uses ||--o{ to show a one-to-many relationship; cardinality is inferred from the FK side (always "many") and the referenced PK side (always "one"). Column metadata like PK, FK, and NOT NULL is added as a suffix so the diagram reads cleanly.
Examples
CREATE TABLE users (id INT PRIMARY KEY, email VARCHAR(255));
CREATE TABLE orders (
id INT PRIMARY KEY,
user_id INT REFERENCES users(id),
total DECIMAL(10,2)
);
erDiagram
users {
INT id PK
VARCHAR email
}
orders {
INT id PK
INT user_id FK
DECIMAL total
}
users ||--o{ orders : "user_id"
FAQ
Does it pick up composite primary keys?
Yes. Both inline PRIMARY KEY per-column constraints and table-level PRIMARY KEY (a, b) clauses are recognised; every member of a composite key gets the PK marker.
What if my DDL has indexes, triggers, or comments?
Anything that isn't a column definition or constraint is ignored. The converter focuses on what affects the ER diagram, so noise from CREATE INDEX or COMMENT ON won't trip it up.
Can I get DBML output too?
This tool emits Mermaid only. For DBML, render the same schema with the DBML renderer instead — most teams pick one notation and stick to it.