Runs 100% in your browser
The SQL formatter that actually reads your query
Paste any SQL — SELECT, CTEs, subqueries, window functions — and get clean, indented, readable output instantly. No login. No data uploaded. Works offline.
Postgres, MySQL, SQL Server, SQLite, BigQuery
Nothing leaves your device
Free forever
How the formatter works
This tool is a pure client-side SQL beautifier. Your query is tokenized inside your browser — keywords, identifiers, string literals, comments, and operators are identified, then reassembled with consistent indentation, aligned clauses, and line breaks at every major boundary (SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, UNION). CTEs, subqueries, and CASE expressions are indented recursively. Nothing is uploaded — the JavaScript that runs the formatter is the same code that renders this page.
Supported patterns
SELECT with any combination of JOINs (INNER, LEFT, RIGHT, FULL, CROSS)
- CTEs:
WITH x AS (…), y AS (…) SELECT …
- Subqueries in
SELECT, FROM, and WHERE clauses
- Window functions:
ROW_NUMBER() OVER (PARTITION BY … ORDER BY …)
CASE expressions, nested
UNION, UNION ALL, INTERSECT, EXCEPT
INSERT, UPDATE, DELETE, MERGE
- Multi-statement scripts separated by semicolons
- Single-line (
-- …) and block (/* … */) comments preserved in place
What it does not do
This is a formatter, not a validator or an execution planner. It doesn’t check whether your SQL is syntactically valid for a specific dialect, doesn’t rewrite queries for performance, and doesn’t evaluate expressions. If your query has a syntax error, the formatter tries to preserve the structure as-is rather than fail silently — but it can’t always guess intent. Vendor-specific procedural syntax (PL/pgSQL, T-SQL blocks) formats less cleanly than pure DML.
Frequently Asked Questions
How does this SQL formatter work?+
It runs entirely in your browser using vanilla JavaScript. Paste any SQL query and it identifies keywords, joins, subqueries, CTEs, and clauses, then reformats them with consistent indentation, uppercased keywords, and line breaks in the right places. Nothing is uploaded to a server — your queries never leave your machine.
Does the SQL formatter work with Postgres, MySQL, SQL Server, and SQLite?+
Yes. The formatter uses a dialect-agnostic approach that handles standard SQL syntax used across Postgres, MySQL, SQL Server, SQLite, BigQuery, Snowflake, and Redshift. It handles common vendor-specific keywords (LIMIT, TOP, OFFSET), CTEs, window functions, and JSON operators.
Is my SQL query sent to a server?+
No. The formatter is entirely client-side JavaScript. Nothing is uploaded, logged, or stored anywhere off your device. Safe to use for queries that include real table names, schemas, or business logic you don’t want to leak.
Can I customize the indentation and case?+
Yes. Choose 2 or 4 space indent (or tabs), and toggle keyword case (UPPERCASE, lowercase, PascalCase). Comma placement (leading or trailing) is also configurable. The formatter remembers your last-used settings via localStorage.
What SQL patterns does the formatter handle?+
SELECT / FROM / JOIN / WHERE / GROUP BY / HAVING / ORDER BY / LIMIT, CTEs (WITH ... AS), subqueries in SELECT/FROM/WHERE, UNION / INTERSECT / EXCEPT, CASE expressions, window functions (OVER, PARTITION BY), and INSERT/UPDATE/DELETE statements.
Why format SQL at all?+
Formatted SQL is drastically easier to review, debug, and share with teammates. A 60-line SELECT with 8 joins is hard to read as a wall of text but readable when properly indented. Code review comments become more precise. Diffs stay clean. And it forces you to look at the structure of your query rather than glossing over it.