About the SQL Formatter
Queries copied from logs, ORMs, or application code usually arrive as one long line that is hard to read. This SQL Formatter breaks the query into one clause per line, uppercases the main keywords, and puts each comma-separated item on its own indented line.
How it works
The query is split into tokens: quoted strings, quoted identifiers, comments, punctuation and words. Because strings and comments are separate tokens, commas, keywords and spaces inside them are never touched. Keywords are then converted to the case you choose.
The formatter writes each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOINs and so on) on a new line with its contents indented beneath it, puts AND and OR conditions on their own lines (except inside BETWEEN), and gives each comma-separated column its own line. A subquery in parentheses gets its own indented block. Minify uses the site's SQL minifier, which also keeps strings intact.
How to use
- 1
Choose Format or Minify.
- 2
Pick the keyword case and indentation.
- 3
Paste your SQL or open a .sql file.
- 4
Copy the result or download it. Your options are kept in the page link.
Worked examples
Tidying a SELECT query
A query copied from an application log.
Each clause starts a new line, keywords are uppercased, and the second selected column is indented under SELECT.
Formatting an UPDATE statement
Making a multi-column update easier to review before running it.
Frequently asked questions
Does this work with different SQL dialects?+
Mostly yes. It works by recognizing common keywords, so standard queries in MySQL, PostgreSQL, SQLite, or SQL Server format the same way. Dialect-specific keywords not on its list are left as they are.
Will formatting change how my query executes?+
No. Only whitespace and keyword case change, and strings, quoted identifiers and comments are kept exactly as written.
Does it uppercase all keywords?+
It changes the case of SQL keywords and common functions such as COUNT and COALESCE, to UPPER or lower as you choose, or leaves them as typed. Table and column names keep their case.
Can it minify a query too?+
Yes. Click Minify to collapse the query onto one line and remove spaces around parentheses and commas.
How are joins formatted?+
It isn't any more. Compound joins like LEFT JOIN and INNER JOIN stay together on one line, with their ON condition indented below.