Generate ER Diagram from SELECT Queries (JOIN Analysis Tool)

Published: (March 23, 2026 at 01:36 AM EDT)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

  • Too many JOINs to understand the structure
  • Hard to visualize table relationships
  • No ER diagram available

I had the same problem, so I built a tool that generates ER diagrams directly from SELECT queries.

👉 Try it here: SQL2ER – trancelens.com

What This Tool Does

The tool analyzes JOIN conditions (e.g., u.id = o.user_id) and converts them into relationships between tables, producing an ER diagram without requiring any DDL.

Example

SELECT
  u.name,
  o.id,
  p.name
FROM users u
JOIN orders o ON u.id = o.user_id
JOIN order_items oi ON o.id = oi.order_id
JOIN products p ON oi.product_id = p.id;

The tool parses the JOIN conditions and visualizes the connections between users, orders, order_items, and products.

Why This Is Useful

  • In real‑world scenarios you often only have SELECT queries.
  • You may be analyzing legacy systems.
  • You need a quick way to understand relationships.

👉 This tool works without any DDL.

Key Features

  • No installation required (runs in the browser).
  • Works with plain SELECT queries.
  • Supports multiple JOINs.
  • Handles table aliases.

How It Works

  1. Input: A SELECT query.
  2. Parsing: The tool extracts table1.column = table2.column join conditions.
  3. Output: It builds connections between tables and renders an ER diagram.

Use Cases

  • Understanding legacy systems.
  • SQL code reviews.
  • Learning database relationships.
  • Debugging complex queries.

Try It Yourself

Visit the site, paste your SQL, and see the structure instantly.

Final Thoughts

Generating ER diagrams from SELECT queries turned out to be surprisingly useful in practice. If you work with SQL regularly, this tool can save you a lot of time.

Feedback

I’d love to hear your feedback.

0 views
Back to Blog

Related posts

Read more »

Introducing Database Traffic Control

Postgres has a fundamental gap when it comes to managing query traffic. When an unexpected spike of bad queries, or runaway workload hits your database, Postgre...