SQL DDL to Diagram

Turn CREATE TABLE statements into an ER diagram.

SQL DDL to Diagram reads CREATE TABLE statements and draws an entity relationship diagram. It also shows the Mermaid erDiagram text it generated and lists the foreign key relationships it found.

What is an ER diagram generated from DDL?

DDL is the part of SQL that defines structure. CREATE TABLE statements list columns, types and constraints such as PRIMARY KEY, NOT NULL, UNIQUE and FOREIGN KEY. An entity relationship diagram shows the same information visually: each table is a box of columns, and each foreign key is a line to the table it references. This tool contains a small, tolerant parser written for the common syntax of MySQL, PostgreSQL and SQLite. It reads tables and columns, picks up primary, unique and foreign keys, turns them into a Mermaid erDiagram, and renders that with Mermaid. A relationship is drawn as one-to-many by default, as one-to-one when the foreign key column is unique or is the whole primary key, and with an optional marker on the parent side when the foreign key column allows NULL. It is a helper for reading a schema, not a full SQL parser, and its limits are listed in the tips and errors below.

How to use SQL DDL to Diagram

  1. Paste the DDL Replace the sample in the SQL DDL (CREATE TABLE statements) box with your own schema. Use the clear button to empty the box.
  2. Read the ER diagram The ER diagram preview renders after a short pause. Primary keys show PK, foreign key columns FK and single-column unique columns UK.
  3. Check the relationships Compare the Relationships list with the SQL. Each line shows child.column -> parent and whether it is one-to-one or many-to-one, with optional added when the column allows NULL.
  4. Fix reported problems If a red box says N statements could not be parsed, read each statement and reason, then edit the SQL or remove the unsupported clause.
  5. Export Click Download SVG or Download PNG for the image (er-diagram.svg or er-diagram.png), or use the copy and download buttons next to Mermaid erDiagram source to take the text.

Frequently asked questions

Is my schema uploaded?

No. The SQL is parsed in the page, and the generated Mermaid text is rendered in the page as well.

Which SQL dialects work?

The parser targets common MySQL, PostgreSQL and SQLite CREATE TABLE syntax, including quoted identifiers with backticks, double quotes or square brackets. Vendor-specific features beyond that may be skipped or reported.

How are relationship types chosen?

Every foreign key becomes a parent-to-child line. It is one-to-one when the foreign key is a single unique column or covers the whole primary key, otherwise one-to-many. The parent side is marked optional when every foreign key column allows NULL and is not part of the primary key.

Does it connect to a database?

No. It only reads the DDL text you paste.

Are indexes, defaults and CHECK constraints shown?

No. Only table names, column names and types, PK, FK and UK markers and relationships are drawn. Length and precision are dropped from types, so VARCHAR(255) is shown as VARCHAR.

Why does the diagram not show a table I pasted?

Either its statement was listed in the red error box, or a parenthesis problem in an earlier statement swallowed it. Fix the first reported statement and look again.