SQL Formatter
Paste messy or one-line SQL and instantly get it beautified with clean indentation and consistent keyword casing — for the database dialect you actually use. Copy the result with one tap and move on. No account, no upload, no waiting.
What is the SQL Formatter?
The SQL Formatter is a free online tool that takes raw, cramped, or one-line SQL and turns it into clean, consistently indented, easy-to-read code. You paste a query, pick the database dialect you actually work with, and the tool re-prints it with each clause on its own line, columns lined up, and reserved keywords cased the way your team prefers. It is built for the everyday reality of working with SQL: you copy a query out of an application log, an ORM, or a teammate's message, and it arrives as an unreadable wall of text. This tool makes it legible in one second.
Why format SQL at all?
Readable SQL is easier to review, debug, and trust. When SELECT, FROM, JOIN, and WHERE each sit on their own line and nested conditions are indented, you can scan the query's shape at a glance, spot a missing join condition, and explain it to a colleague without squinting. Consistent formatting also reduces noise in code review and version control: when everyone formats the same way, a diff shows real logic changes instead of whitespace churn. Formatting never changes what a query does, it only changes how it looks, so there is no risk in cleaning up a query before you run it.
How to use it
- Paste or type your SQL into the input box (for example a query copied from a slow-query log or generated by an ORM).
- Choose your dialect — Standard SQL, MySQL, PostgreSQL, SQLite, MariaDB, SQL Server, Oracle, BigQuery, or Snowflake — so keywords are recognized correctly.
- Pick how you want it to look: keyword casing (UPPER, lower, or preserve) and indentation (2 spaces, 4 spaces, or tabs).
- The formatted result appears as you type. Click Format to re-run after changing options.
- Click Copy to grab the result and paste it wherever you need it. Done — no account, no upload, no waiting.
The whole flow is designed so you get clean SQL immediately and move on.
The method behind it
Under the hood the tool tokenizes your SQL by splitting it into keywords, identifiers, strings, numbers, and operators, and then re-prints those tokens according to the rules of the dialect you selected. Because it parses real tokens rather than doing a blind search-and-replace, it knows that a word like ORDER inside a string literal is data, not a keyword, and leaves it alone. Each major clause is placed on a new line, list items are broken out and indented, and reserved words are cased to your preference. The output is the same query, reshaped purely for readability. This formatting runs entirely in your browser using a mature open-source SQL formatting engine, so nothing about your query is sent anywhere.
Dialect differences
SQL is a family of closely related languages, not one universal syntax. PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery, and Snowflake each add their own keywords, functions, quoting styles, and clauses on top of the standard. Choosing the dialect that matches your database lets the formatter recognize those database-specific keywords and lay the query out the way that engine's grammar expects, instead of applying a generic best guess. If you are not sure, Standard SQL is a safe default that handles ordinary SELECT, JOIN, GROUP BY, and subquery patterns well.
Example
Input — one cramped line:
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 Output — PostgreSQL, uppercase keywords, 2-space indent:
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 The query is identical in behavior — only its shape changed.
Common use cases
- Reading generated SQL — ORMs and query builders emit dense single-line SQL; format it to understand what your code actually sends to the database.
- Debugging slow queries — paste a query from a slow-query log and reshape it so you can reason about the joins and filters.
- Code review — beautify before pasting SQL into a pull request or ticket so reviewers see logic, not whitespace.
- Learning and teaching — formatted queries make it far easier to explain how a join or subquery works.
- Standardizing a codebase — apply consistent casing and indentation so every query in the repo looks the same.
- Cleaning up copied snippets — turn a query pasted from chat or a transcription into something you can actually run.
Why use this one
Many online SQL formatters apply a single generic style and, more importantly, send your query to a server to format it. That is a quiet risk, because SQL frequently exposes your real schema: table names, column names, and the structure of sensitive data. This tool formats everything in your browser, so your SQL never touches a server, is never uploaded, and is never stored. It also supports nine common dialects, gives you control over keyword casing and indentation, runs instantly with no round-trip, works on mobile, and needs no signup. When your data is in JSON instead, reach for the JSON Formatter; to compare two versions of a query line by line, use the Text Diff Checker; and to build or test the patterns you put inside LIKE and REGEXP clauses, try the Regex Tester.
Frequently asked questions
Is my SQL safe — is anything uploaded to a server?
No. All formatting happens entirely inside your browser using JavaScript. Your SQL is never sent to, stored on, or seen by any server, so it is safe to paste queries that reference your real table names, column names, or internal schema.
Why does choosing the right dialect matter?
Different databases have their own keywords, functions, and quoting rules. Picking the matching dialect — for example PostgreSQL versus MySQL versus SQL Server — lets the formatter recognize those keywords correctly and indent the query the way that database's syntax expects, so the result is accurate rather than generic.
Can I control keyword casing and indentation?
Yes. You can force reserved keywords like SELECT, FROM, and WHERE to uppercase or lowercase (or leave them as you typed them), and pick 2-space, 4-space, or tab indentation to match your team's style guide.
Does the formatter change what my query does?
No. Formatting only adjusts whitespace, line breaks, indentation, and keyword casing for readability. It does not rewrite logic, reorder clauses, or alter the meaning of your query — the SQL runs exactly the same as before.
Does it work on mobile?
Yes. The tool is fully responsive and works in any modern mobile browser, so you can clean up and read SQL from your phone without installing an app.