Developer Tools

SQL Formatter

SQL formatter that puts each clause on its own line, indents columns and conditions, uppercases keywords and can minify a query to one line.

Input SQL
Output

    

This SQL formatter puts each major clause of a query (SELECT, FROM, JOIN, ON, WHERE, GROUP BY, ORDER BY and so on) on its own line, with each selected column and each AND or OR condition indented below it. Keywords are uppercased unless you untick Uppercase Keywords, the output is color-highlighted, and Minify does the reverse, putting the query on one line. Use it as a SQL beautifier for queries copied from logs, ORM output or old scripts.

How to use the SQL formatter

  1. Paste your raw or minified SQL query into the input editor, or press Try Example.
  2. Choose an indent of 2 spaces, 4 spaces or a tab, and untick Uppercase Keywords if you want keywords left as you typed them.
  3. Click Format / Prettify, or press Ctrl+Enter (Cmd+Enter on a Mac) in the input box.
  4. Review the highlighted output. A subquery in brackets moves to its own indented line but is not split into clauses, and comments stay on lines of their own.
  5. Copy the clean SQL with the Copy button.

Example: before and after

A one-line query, as it might come out of a log or an ORM:

select o.id, c.name, sum(oi.qty * oi.price) as total from orders o join customers c on c.id = o.customer_id left join order_items oi on oi.order_id = o.id where o.status = 'paid' and o.created_at >= '2026-01-01' group by o.id, c.name order by total desc limit 10;

Formatted with a 2-space indent and Uppercase Keywords ticked:

SELECT o.id,
   c.name,
   SUM( oi.qty * oi.price) AS total
FROM orders o
JOIN customers c
ON c.id = o.customer_id
LEFT JOIN order_items oi
ON oi.order_id = o.id
WHERE o.status = 'paid'
  AND o.created_at >= '2026-01-01'
GROUP BY o.id,
   c.name
ORDER BY total DESC
LIMIT 10;

ON starts its own line at the same level as its JOIN, and the string '2026-01-01' is untouched. Two small quirks show up: SUM gains a space after its bracket, which databases ignore, and the extra columns after SELECT and GROUP BY are indented one space more than the AND condition.

Options and the minifier

ControlWhat it does
Indent2 spaces, 4 spaces or a tab for indented lines
Uppercase KeywordsCapitalizes keywords and common functions such as COUNT and COALESCE; untick to keep your own case
Format / PrettifyOne clause per line
MinifyOne line, comments removed, keywords left in your case
Try ExampleLoads a longer query with joins, NOT EXISTS, GROUP BY and HAVING

The line under the editor reports the input and output size in characters and bytes. Minify keeps single spaces around operators such as =, which suits pasting a query into application code or a config file.

Dialects: what to check after formatting

There is no dialect setting. Standard queries format well and MySQL backtick names come through intact, but a few dialect forms get spaces inserted that break them. This is what the formatter does to each:

InputFormattedResult
created_at::datecreated_at : : DATEPostgreSQL cast broken
$1$ 1Placeholder broken
[Order Total][ ORDER Total ]SQL Server name changed
`user name``user name`Fine

Minify leaves all of these intact, so use it when a query has to run exactly as written. Neither mode of the SQL formatter checks syntax: SELEC id FRM users comes back unchanged, with no error, so a query that formats cleanly can still fail on the server.

Common uses

Format SQL before a code review so each join and filter sits on its own line. When two versions of a query need comparing, run both through the SQL formatter with the same settings and paste them into the diff checker, which then shows only the lines that changed. In SQL files kept in version control, a changed condition becomes a single changed line.

A SQL query formatter is often one step in a data job. Query results exported as CSV can go through the CSV to JSON converter, and API responses belong in the JSON formatter; the guide to formatting JSON in your browser covers that side. Other code tools are on the developer tools page.

Frequently Asked Questions

Why should I format my SQL queries?
A query with one clause per line is quicker to read and review, and the join conditions and filters are easy to find. In SQL files kept under version control, a changed condition then shows up as a single changed line in the diff.
Does the formatter change how my query runs?
Usually not. It changes whitespace and, with Uppercase Keywords ticked, the case of keywords, which databases treat as case-insensitive. Quoted strings are never touched. The exceptions are PostgreSQL :: casts and $1 placeholders and SQL Server [bracketed] names, which come out with spaces inside them and then fail or point to a different name. Minify leaves all three intact.
Which SQL dialects are supported?
There is no dialect menu. The formatter uses one list of common keywords, mostly standard SQL plus a few dialect words such as TOP, AUTO_INCREMENT, RETURNING and NVL. Everyday queries for MySQL, PostgreSQL, SQL Server and SQLite format well, and MySQL backtick names are handled. Check the output if your query uses :: casts, $1 parameters or square-bracket names.
Can I use this tool to minify SQL?
Yes. Minify removes comments and line breaks and puts the query on one line, keeping single spaces around operators such as =. That suits pasting a query into application code or a config file.
Is my query sent to a server when I use this SQL formatter online?
No. Formatting, minifying and highlighting all run in JavaScript inside the page, and the tool makes no network requests with your SQL. Table names, column names and values in your queries stay on your device, so you can format production queries without sending them anywhere.