SQL Formatter — Pretty-Print and Beautify SQL Queries Online
🔒 Runs in your browser — nothing is sent to a serverSQL formatter that turns any messy or single-line SQL query into a clean, readable structure in one click. Pick your dialect — PostgreSQL, MySQL, T-SQL, Oracle, BigQuery, Snowflake and more — and the formatter rewrites the query with proper indentation, top-level keywords on their own lines and consistent casing. Everything runs 100% inside your browser; your queries never leave your device, nothing is uploaded or logged.
When to use a SQL formatter online
You reach for a SQL formatter any time a query arrives unreadable: a one-liner copied from a slow-query log, an ORM-generated statement that ships everything on a single line, a migration script auto-generated by a framework, an analytical query pulled from a notebook cell, or an ad-hoc report you need to put into a code-review PR. Browser-local formatting matters when the query contains sensitive table or column names, internal report definitions, customer-segment filters or any SQL referencing schemas you would rather not paste into a remote SaaS formatter. The formatted output sits ready for the PR description, the runbook or the team Slack.
How SQL pretty-printing works under the hood
SQL pretty-printing is an AST-driven pipeline. The `sql-formatter` library tokenises the query with a dialect-aware lexer that knows each engine's keywords, operators and identifier quoting rules; the parser then groups tokens into clauses (SELECT, FROM, WHERE, JOIN), expressions, subqueries and CTEs. The renderer walks the resulting structure: top-level keywords land on their own line at column zero, comma-separated select lists indent under each keyword, subqueries and CTEs gain one extra indent level per nesting depth, and the configured keyword case is applied to every reserved word. Comments, string literals, quoted identifiers and parameter placeholders pass through untouched. The whole pipeline runs in your browser in milliseconds, even on multi-CTE analytical queries.
Examples
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = true group by u.id, u.name order by orders desc limit 25;SELECT
u.id,
u.name,
COUNT(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = TRUE
GROUP BY
u.id,
u.name
ORDER BY
orders DESC
LIMIT
25;insert into tools (slug, name, role) values ('sql-formatter', 'sql formatter', 'pretty print sql for review');INSERT INTO
tools (slug, name, role)
VALUES
(
'sql-formatter',
'sql formatter',
'pretty print sql for review'
);