Skip to main content

SQL to ER Diagram

Paste your CREATE TABLE statements to generate an interactive ER diagram

SQL Schema (CREATE TABLE)

SQL40 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

ER Diagram

users
id
SERIAL
email
VARCHAR
name
VARCHAR
role_id
INTEGER ) →roles.id
created_at
TIMESTAMP
roles
id
SERIAL
name
VARCHAR
posts
id
SERIAL
title
VARCHAR
body
TEXT
author_id
INTEGER →users.id
published
BOOLEAN
created_at
TIMESTAMP
comments
id
SERIAL
post_id
INTEGER →posts.id
author_id
INTEGER ) →users.id
body
TEXT
created_at
TIMESTAMP
tags
id
SERIAL
name
VARCHAR
post_tags
post_id
INTEGER →posts.id
tag_id
INTEGER →tags.id

Foreign Key Relationships

users.role_id → roles.id
posts.author_id → users.id
comments.post_id → posts.id
comments.author_id → users.id
post_tags.post_id → posts.id
post_tags.tag_id → tags.id
📋 Mermaid ER Syntax (copy to AI tools)
erDiagram
  users {
    SERIAL id PK  NOT NULL
  }
  users {
    VARCHAR email  NOT NULL
  }
  users {
    VARCHAR name  NOT NULL
  }
  users {
    INTEGER ) role_id FK  NOT NULL
  }
  users {
    TIMESTAMP created_at  NOT NULL
  }
  roles {
    SERIAL id PK  NOT NULL
  }
  roles {
    VARCHAR name  NOT NULL
  }
  posts {
    SERIAL id PK  NOT NULL
  }
  posts {
    VARCHAR title  NOT NULL
  }
  posts {
    TEXT body  NOT NULL
  }
  posts {
    INTEGER author_id FK  NOT NULL
  }
  posts {
    BOOLEAN published  NOT NULL
  }
  posts {
    TIMESTAMP created_at  NOT NULL
  }
  comments {
    SERIAL id PK  NOT NULL
  }
  comments {
    INTEGER post_id FK  NOT NULL
  }
  comments {
    INTEGER ) author_id FK  NOT NULL
  }
  comments {
    TEXT body  NOT NULL
  }
  comments {
    TIMESTAMP created_at  NOT NULL
  }
  tags {
    SERIAL id PK  NOT NULL
  }
  tags {
    VARCHAR name  NOT NULL
  }
  post_tags {
    INTEGER post_id FK  NOT NULL
  }
  post_tags {
    INTEGER tag_id FK  NOT NULL
  }
  users ||--o{ roles : "role_id"
  posts ||--o{ users : "author_id"
  comments ||--o{ posts : "post_id"
  comments ||--o{ users : "author_id"
  post_tags ||--o{ posts : "post_id"
  post_tags ||--o{ tags : "tag_id"

About the SQL To Er Diagram

A CREATE TABLE script describes your schema, but understanding it - especially a schema you inherited - requires seeing it: which tables exist, what keys link them, where the joins live. An ER diagram turns DDL into a picture your whole team can read.

Paste CREATE TABLE statements and get an interactive entity-relationship diagram with primary and foreign keys mapped automatically. Export as Mermaid to drop the diagram into docs, PRs, or an AI assistant. Parsing happens client-side - proprietary schemas never leave your machine.

How to use

  1. Paste your CREATE TABLE statements (one or many).
  2. The diagram renders with tables as nodes and foreign keys as edges.
  3. Inspect any relationship by selecting a table.
  4. Export as Mermaid for docs, GitHub markdown, or AI tools.

Frequently Asked Questions

Which SQL dialects can I paste? ▾

Standard CREATE TABLE syntax works - PostgreSQL, MySQL, SQLite, and SQL Server definitions all parse. Dialect-specific types are shown as declared; relationships come from FOREIGN KEY ... REFERENCES clauses.

Can I export the diagram? ▾

Yes, as Mermaid code. Mermaid renders natively in GitHub markdown, Notion, Obsidian, and most documentation tools, so the diagram stays maintainable alongside your schema.