Skip to content
← Blog
HomeBlogDDL to ER Diagram Tutorial

How to Generate an ER Diagram from SQL DDL: Step-by-Step Tutorial

By Bill Crawford ยท March 2, 2026 ยท 5 min read  ยท  Last updated March 02, 2026

This tutorial walks through generating an ER diagram from SQL CREATE TABLE statements using the DDL to ER Diagram tool. You will paste DDL, generate the diagram, read the relationship lines, rearrange tables, and export to SVG, PNG, and Mermaid.

๐Ÿ”ง Open the tool to follow along:

Open DDL to ER Diagram

Table of Contents

  1. 1 Prepare Your DDL
  2. 2 Paste and Generate
  3. 3 Read the Diagram
  4. 4 Rearrange and Focus
  5. 5 Review the Mermaid Output
  6. 6 Export the Diagram
  7. 7 Check the Warnings Tab
  8. Common Pitfalls
  9. Related Tools & Guides

1 Prepare Your DDL

You need one or more CREATE TABLE statements. These can come from your database client's "Script Table As" feature, a migration file, or a schema dump. Here is a simple example with two related tables:

CREATE TABLE Customers (
    CustomerID INT PRIMARY KEY,
    Name NVARCHAR(100) NOT NULL,
    Email VARCHAR(255)
);

CREATE TABLE Orders (
    OrderID INT PRIMARY KEY,
    CustomerID INT NOT NULL,
    OrderDate DATE,
    Total DECIMAL(10,2),
    FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);

Tip: Include all related tables in a single paste. If you only paste the Orders table without Customers, the tool will flag a warning that the referenced table is missing.

2 Paste and Generate

Open the tool and paste your DDL into the left-hand SQL editor. You can also click ๐Ÿ“‚ Load .sql to import a file directly from your filesystem. Click โ–ถ Generate Diagram.

The status strip below the editor will show: โœ“ Parsed 2 tables, 1 relationship. If there are issues, they will appear as warnings or errors โ€” check the Warnings tab on the right panel for details.

3 Read the Diagram

The diagram panel shows each table as a dark card with its columns listed inside. Key columns are color-coded:

Relationship lines connect tables through their foreign keys. The crow's foot symbol (a three-pronged fork) on one end indicates the "many" side of the relationship โ€” the table that contains the foreign key. The single-line end indicates the "one" side โ€” the table being referenced.

Hover over any relationship line to see a tooltip showing the exact column mapping, such as Orders.CustomerID โ†’ Customers.CustomerID.

4 Rearrange and Focus

The diagram is interactive. You can:

5 Review the Mermaid Output

Click the Mermaid tab to see the generated Mermaid ER syntax. This is a text representation of the same diagram that can be rendered in GitHub Markdown, Notion, Obsidian, and other platforms that support Mermaid.

To use it in a GitHub README, wrap the text in a code fence:

```mermaid
erDiagram
  Customers {
    INT CustomerID PK
    NVARCHAR(100) Name
    VARCHAR(255) Email
  }
  Orders {
    INT OrderID PK
    INT CustomerID FK
    DATE OrderDate
    DECIMAL(10,2) Total
  }

  Customers ||--|{ Orders : "CustomerID"
```

Click ๐Ÿ“‹ Copy Mermaid to copy the syntax to your clipboard.

6 Export the Diagram

The toolbar above the diagram provides two image export options:

7 Check the Warnings Tab

The Warnings tab shows any issues the parser encountered:

Common Pitfalls

๐Ÿ”ง Try it yourself โ€” paste any DDL and get an ER diagram in seconds.

Open DDL to ER Diagram
BC
Bill Crawford
Founder, Data Conversion Center

Bill builds browser-based developer tools that prioritize privacy and speed. With a background in data engineering and API design, he focuses on making common developer tasks faster and more accessible.