DEV Community

pomuchan02
pomuchan02

Posted on

Generate ER Diagram from SELECT Queries (JOIN Analysis Tool)

No installation required. Runs entirely in your browser.

Introduction
When working with existing systems, have you ever struggled with complex SQL like this?

  • 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

↓

What This Tool Does
You can paste a SELECT query, and it will automatically generate an ER diagram based on JOIN relationships.

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;
Enter fullscreen mode Exit fullscreen mode

πŸ‘‡

The tool analyzes JOIN conditions like:

u.id = o.user_id
Enter fullscreen mode Exit fullscreen mode

and converts them into relationships between tables.

Why This Is Useful
Most existing tools (like DDL-based ER generators) require CREATE TABLE statements.

However, in real-world scenarios:

  • You often only have SELECT queries
  • You’re analyzing legacy systems
  • You want to quickly understand relationships πŸ‘‰ This tool works without any DDL

Key Features

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

How It Works
The logic is simple:

SELECT query
↓
Parse JOIN and ON clauses
↓
Extract relationships
↓
Generate ER diagram
Specifically, it detects patterns like:

table1.column = table2.column
Enter fullscreen mode Exit fullscreen mode

and builds connections from them.

Use Cases

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

Try It Yourself
πŸ‘‰ http://trancelens.com/sql2er/en/index.html

Paste your SQL and see the structure instantly.

Final Thoughts
There are many tools that generate ER diagrams from CREATE statements.

But generating them from SELECT queries turned out to be surprisingly useful in practice.

If you deal with SQL regularly, this might save you a lot of time.

Feedback
I’d love to hear your fee

Top comments (0)