A SQL formatter takes a cramped, single-line query and beautifies it: keywords are cased consistently, major clauses like SELECT, FROM, WHERE and JOIN start on their own lines, and subqueries are indented so the structure is obvious. The tool above does this entirely in your browser. Paste SQL on the left, get readable, indented SQL on the right, then copy or download it. It is a formatter, not a validator or a database client, so it never runs your query and nothing you paste is transmitted anywhere.
What does a SQL formatter do?
SQL is often written or generated as one long line, especially inside application code, log files, or ORM output. That is fine for a machine but hard for a person to read or review. A formatter parses the query into tokens, then re-lays them out with predictable rules: one clause per line, consistent indentation, and uniform keyword casing. The result is easier to scan, easier to diff in code review, and easier to debug, without changing the tokens the database will actually receive.
What this tool changes and what it leaves alone
The formatter only touches presentation. It adjusts three things: whitespace (spaces, tabs, and line breaks), indentation depth, and the casing of recognised keywords. Everything else is preserved exactly:
- Keywords are upper-cased by default. Switch the Keywords selector to lowercase, or to Preserve to leave them untouched.
- Identifiers such as table and column names keep their original casing, always.
- Strings and quoted names are treated as single units. A single-quoted string, a double-quoted or backtick or bracketed identifier is never re-cased or split across lines, and doubled-quote escapes like
'it''s'are handled correctly. - Comments โ both line comments (
--and#) and block comments (/* ... */) โ are kept intact.
How it lays out a query
Major clauses each begin on a fresh line at the base indent, joins hang below the tables they attach to, and each ON, AND, and OR condition is indented one level so the logic reads top to bottom. Columns in a SELECT list are placed one per line. Parenthesised subqueries are indented as a block so you can see where they start and end. A worked example:
SELECT
u.id,
u.name,
(
SELECT
count(*)
FROM orders o
WHERE o.user_id = u.id
) AS order_count
FROM users u
LEFT JOIN profiles p
ON p.user_id = u.id
WHERE u.status = 'active'
AND u.created_at > '2024-01-01'
GROUP BY u.id
ORDER BY order_count DESC
LIMIT 20;
Multiple statements separated by semicolons are each formatted and spaced apart with a blank line.
Common use cases
- Reading a minified query pulled from application logs or an ORM’s debug output.
- Cleaning up hand-written SQL before committing a migration or a stored view.
- Making two queries easier to diff by formatting both with the same settings first.
- Presenting a query in documentation or a code review with consistent, readable indentation.
Formatter, not a validator or an executor
It is worth being explicit: this tool does not check whether your SQL is correct, and it does not run it. There is no database connection of any kind. It will happily format a query with a typo, a missing table, or a logic error, because its only job is layout. If the input has genuinely broken structure โ for example unbalanced parentheses โ the output may look odd, but the tool still returns your tokens in the original order, so nothing is silently dropped. Always review the formatted result before running it against a real database.
Which dialects work?
Because the formatter works by structure rather than by enforcing one grammar, it is broadly dialect-agnostic. It recognises the common keywords and the quoting styles used across PostgreSQL, MySQL, SQL Server, SQLite, and others โ double quotes, backticks, and square brackets for identifiers; single quotes for strings. It does not, however, guarantee that a given construct is valid in your specific database. For unusual vendor-specific syntax the layout is a best effort built on heuristics, not a complete parser.
Is it private?
Yes โ your SQL never leaves your browser. The tokenising and re-formatting happen on your device with no server round-trip, no logging, and no third-party analytics on this page. For extra assurance you can load the page and then work offline, or inspect the client-side source. As a general habit, avoid pasting queries that embed live credentials or secrets into any online tool you have not verified.