Paste a SQL query into the left pane and click SQL Formatter and Beautifier; the right pane uppercases the major keywords, breaks each clause onto its own line, and indents nested subqueries so the statement is easy to read.
SQL Formatter & Beautifier
Format messy SQL in the browser with clause breaks and uppercase keywords.
Paste a query, click Format, and copy the indented result. Formatting runs locally - nothing is uploaded.
This page does not validate dialect rules, run queries, or rewrite against a schema.
How SQL Formatter & Beautifier breaks up commas, joins, and nested subqueries
SQL Formatter & Beautifier tracks how deep the text sits inside parentheses as it reads through a query. Every comma inside a SELECT list, a function call, or an INSERT VALUES list gets its own line, indented to match that depth - so a comma inside a nested subquery lands one indent level deeper than a comma in the outer query. Multi-word clauses are treated as one unit rather than split awkwardly: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, and CROSS JOIN each move onto a fresh line together, and the same grouping applies to GROUP BY and ORDER BY. Parentheses themselves are never removed or reformatted - opening and closing brackets stay exactly where you typed them, and the indent depth simply steps back down when a closing bracket appears. This is why a query with a subquery inside a WHERE ... IN (...) clause comes out with the inner SELECT indented further than the outer one, instead of flattened onto a single indent level.
What SQL Formatter & Beautifier leaves untouched
Three kinds of text pass through the formatter completely unchanged: single-quoted strings, double-quoted strings, and backtick-quoted identifiers. Whatever a quoted value contains - including a word that looks like a SQL keyword, such as the string literal 'select all' - is copied byte for byte, quote marks included. Line comments starting with -- and block comments wrapped in /* ... */ are preserved the same way, so any notes left in a query survive the format pass. Keyword recognition itself is case-insensitive: typing select, Select, or SELECT all uppercase the same way in the output, but this only applies to the roughly 60 reserved words the formatter recognizes (SELECT, FROM, WHERE, JOIN, GROUP BY, and similar clause and operator keywords) - table names, column names, and string contents never change case. Runs of plain whitespace outside strings and comments collapse to a single space, and three or more blank lines in a row collapse down to one, so a messy paste does not leave oversized gaps in the formatted result.
A worked example: before and after
Paste a query like select id, name, email from users where active = 1 and country in ('US','CA') order by name and the formatter returns it as an indented block: SELECT on its own line, id, name, and email each on a separate indented line under the comma rule, FROM and WHERE each starting a new line, the IN (...) list keeping its own parentheses untouched with 'US' and 'CA' left exactly as typed, and ORDER BY moved onto its own line as a single two-word clause. A one-line query like this one commonly turns into eight or nine formatted lines once every major clause and every top-level comma has been broken out - useful for reading back a query copied from a log file or a compact one-line migration script, where the original line breaks were stripped out entirely.
Frequently Asked Questions
What does SQL Formatter & Beautifier change?
It inserts newlines before major clauses, uppercases common SQL keywords, and indents comma lists. String and comment text stay intact.
Is my query uploaded?
No. Formatting runs in this tab with pure JavaScript.
Does it understand my SQL dialect?
No. It is a text formatter, not a parser that rejects invalid dialect features.
Can it execute the query?
No. There is no database connection and no server round-trip.
Are backtick-quoted identifiers preserved too?
Yes. Backtick-quoted identifiers are preserved exactly like single- and double-quoted strings, so a backtick-quoted column or table name comes through unchanged along with its surrounding backticks.
Does it change select to uppercase if I type it in lowercase?
Yes. Keyword recognition is case-insensitive, so select, Select, and SELECT all uppercase the same way in the output. This only applies to the roughly 60 reserved SQL words the formatter recognizes; table names, column names, and string contents keep whatever case you typed.
How does it indent a subquery inside parentheses?
Each level of parentheses adds one indent level, so a subquery nested inside a WHERE ... IN (...) clause or a function call indents one step deeper than the query around it, rather than flattening everything to the same indent.
Does a long comma-separated column list break onto separate lines?
Yes. Every comma inside a SELECT list, a function call, or an INSERT VALUES list starts a new line, indented to match how deep that comma sits inside parentheses.
What happens if my query has an unmatched quote?
Everything after the stray opening quote is treated as string content until a matching quote appears or the input ends, so one extra quote can silently absorb the rest of the query into the output unchanged. There is no error message, since the formatter never parses or validates SQL - it only tracks quotes, comments, and parenthesis depth.