SQL formatter and beautifier
Indent a query by its nesting, bring keywords to one case, or squeeze the whole thing onto one line for a log, across fifteen dialects.
Drop your files here
.sql, .txt · up to 10 MB
How to Format SQL
- 1
Drop your .sql file
Add the file holding the query. It is read and rewritten inside this browser tab, with nothing sent anywhere.
- 2
Choose a dialect and a case style
Pick one of fifteen dialects, set keyword and identifier case separately, choose the indent width, and decide whether AND and OR start a line or end one.
- 3
Download the formatted query
Save the result as a .sql file named after the original.
Tokens, not regular expressions
The query is split into string literals, quoted identifiers, comments, numbers and words before anything is printed, which is the difference between a formatter and a clever search-and-replace. A literal reading '-- not a comment' keeps its dashes instead of losing half the line, and the three spaces inside 'a b' stay three spaces, because inside a literal every character is data your database will compare against.
It lays out queries, it does not check them
Keyword recognition here is one shared vocabulary plus per-dialect additions, not fifteen complete grammars, so the tool arranges indentation and line breaks rather than telling you whether the statement is valid. Your database is still the authority on that. An unbalanced bracket or quote does not block the result either: you get a warning with the line number and the formatted output anyway, since a missing parenthesis is usually the reason you came here.
Minify for the places code lives
Minify puts a statement on one line for a config value, a log entry or a string in application code. Whitespace collapses outside literals only, and one space always stays between adjacent words so nothing gets welded together.
Your query stays on your computer
Reading the file, tokenising it and printing the result all happen inside this browser tab. Nothing is uploaded and nothing is stored, which matters for a query that carries table names, schema details or a hardcoded value you would rather not paste into someone else's web form.
Frequently asked questions
Which SQL dialects are supported?
Fifteen: standard SQL, MySQL, MariaDB, PostgreSQL, DB2, PL/SQL, N1QL, Redshift, Spark, SQLite, T-SQL, BigQuery, Snowflake, Trino and SingleStoreDB. The choice affects which words are treated as keywords and where line breaks fall.
Will it tell me whether my query is correct?
No, and it does not claim to. The keyword list is a common core plus dialect-specific additions rather than a full grammar for each engine, so the tool indents and wraps what you give it without judging validity. Formatting an unfamiliar query still helps, because misplaced clauses become visible once the nesting is laid out.
What does the unbalanced bracket warning mean?
Parentheses and quotes were counted and did not pair up. You get the line number of the first mismatch, and the query is formatted regardless. Treat the layout as a best guess up to that point; it usually shows where a bracket went missing.
How does minify differ from format?
Format spreads the statement out over lines with indentation matching its nesting, for reading and reviewing. Minify does the opposite and collapses it to one line so it fits in a config file, a log line or a string constant.
Are comments preserved?
By default yes, both the double-dash and the block kind, repositioned to fit the new layout. A separate switch removes them, and it works on tokens, so a literal that merely looks like a comment is left alone.
Can I format several statements at once?
Yes. Statements separated by semicolons are each formatted in turn, and you choose how many blank lines sit between them, from zero to five. The count of statements found is reported with the result.
Why was a deeply nested query refused?
Past twenty levels of nested parentheses the output stops being something anyone can read, and that depth almost always means a bracket was never closed. Rather than emit an unusable staircase, the tool says so directly.
Is there a size limit, and is anything uploaded?
Five million characters per query, which is far more than any hand-written statement. Nothing is uploaded at any size: the whole thing runs locally in your browser, with no server and no account.