SQL Formatter + Explainer + Complexity Meter
Paste or drop any SQL query to format it into clean, readable code, get a plain English explanation with extracted facts, and see a complexity score with a detailed breakdown — all in one tool. Supports Generic SQL, PostgreSQL, MySQL, SQL Server, and SQLite. Everything runs entirely in your browser. No server, no uploads, no AI — pure structural analysis powered by JavaScript.
Formatted SQL
Plain English Explanation
Summary
Breakdown
Extracted Facts
Complexity Score
Errors & Warnings
What This Tool Does
Formats messy SQL into clean, readable code and explains every clause in plain English — in a single step — processed in your browser without uploading anything.
Who This Is For
- Developers who need both readable formatting AND a quick understanding of what an unfamiliar query does
- Technical writers documenting SQL queries for non-technical stakeholders
- Code reviewers who want a formatted version and an explanation before approving a PR
- SQL learners who want to understand complex queries written by others
Example: Input: A minified 5-table JOIN query from a legacy codebase → Output: Formatted, indented SQL plus a plain-English clause-by-clause explanation: "Joins the orders table to users on user_id, filters for completed orders in the last 30 days, groups by region, and returns the count per region"
How the SQL Formatter + Explainer Works
This tool combines three functions into a single interface. The formatter uses the sql-formatter library to beautify your SQL with consistent indentation, keyword casing, and clause separation. The explainer parses the query structure using an AST parser with regex fallback and generates a plain English summary plus a structured breakdown of every clause. The complexity meter scores the query from 0 to 100 based on structural elements like joins, subqueries, window functions, grouping, and filter count.
Supported Dialects
Select your target dialect from the dropdown to get the most accurate formatting and parsing. Supported dialects include Generic SQL (ANSI), PostgreSQL, MySQL, SQL Server (T-SQL), and SQLite. If the AST parser encounters dialect-specific syntax it cannot handle, it falls back to regex-based heuristic analysis so you still get useful results.
Understanding the Complexity Score
The complexity score is calculated from the structural elements of your query. Each element contributes a weighted number of points, capped to prevent runaway scores. Tables contribute up to 20 points (5 per table), joins up to 30 (10 each), subqueries up to 24 (12 each), GROUP BY adds 10, window functions 15, and filters up to 10 (2 each). A simple single-table SELECT scores under 15. A multi-join report with aggregation typically scores 30–50. Complex ETL or analytics queries with CTEs, window functions, and nested subqueries legitimately score 60 and above.
Input Methods
You can paste SQL directly into the editor or switch to the Upload tab and drag-and-drop a .sql or .txt file. Files are read locally using the browser's FileReader API — nothing is uploaded to any server. The file name and size are displayed after loading.
Error Handling
If the parser cannot fully parse your SQL, the Errors tab appears with a friendly message, the original parser error (collapsed by default), and actionable tips such as checking for missing table names after FROM, unclosed quotes, or unsupported dialect syntax. Even when parsing fails, the tool still provides a best-effort explanation and complexity score using regex-based extraction.
Privacy
Your SQL never leaves your browser
All formatting, parsing, explanation, and scoring happen entirely in JavaScript in your browser. There are no network calls, no server-side processing, and no data storage. This tool works fully offline once loaded.
Frequently Asked Questions
Does formatting change how my SQL runs?
No. SQL is whitespace-insensitive. The database engine generates the same execution plan regardless of formatting. Formatting only affects human readability.
Can I format and explain multiple statements at once?
The formatter handles multiple semicolon-separated statements. The explainer and complexity meter analyze the first statement in a multi-statement input. For best results, analyze one statement at a time.
What is the difference between this tool and the standalone formatter or explainer?
This tool combines formatting, explanation, and complexity scoring into a single interface with tabbed output. The standalone SQL Formatter and SQL Query Explainer are also available if you prefer a focused single-purpose tool.
Related Guides & Tutorials
SQL Formatting, Explanation & Complexity Scoring
How formatters, explainers, and complexity meters work together to make SQL readable and maintainable.
TutorialHow to Use the SQL Formatter + Explainer
Step-by-step tutorial for formatting, explaining, and scoring any SQL query in your browser.
GuideWriting Readable SQL
A guide to formatting queries for teams with consistent style and clear structure.
GuideUnderstanding SQL Queries
How query explainers parse SQL to produce summaries and complexity scores.
