SQL Formatter takes a query that has been squashed onto one line, or pasted out of code, and lays it out so you can actually read it: one column per line, clauses lined up, keywords in the case you prefer. It knows 17 database dialects, and it can squeeze a query back onto a single line when you need to paste it somewhere. Everything happens in your browser.
How to format a query
- Paste your SQL into the left box, or open a
.sqlfile. - Choose your dialect, such as PostgreSQL or SQL Server. Your choice is remembered.
- Pick whether keywords are UPPER, lower or left as typed, and 2 or 4 space indents.
- Copy or download the result, or switch to One line to compact it again.
Why the dialect matters
Databases extend SQL in their own ways, so a query that is perfectly valid in BigQuery or SQL Server can look like a syntax error to a plain SQL parser. Choosing the right dialect means things like backtick-quoted names,TOP, array types and window syntax are understood and laid out properly instead of being reported as a problem. If a valid query is rejected, the dialect is the first thing to change.
What it will not change
Formatting only rewrites whitespace, line breaks and keyword case. Everything inside quotes is left byte for byte, so a string containing commas, keywords or even -- is safe, and comments keep their wording and position. The query you get back does exactly what the one you pasted did.
Putting a query on one line
The One line option is for pasting a query into a configuration file, a log entry or a piece of code. Comments are removed by default for a good reason: a -- comment runs to the end of its line, so once everything is on one line it would comment out the rest of the query. If you tick Keep comments, they are converted to the /* … */ form, which is safe on a single line.
Reading a long query
- Start at FROM and JOIN to see which tables are involved, then read WHERE to see what is filtered.
- GROUP BY with HAVING means the filter applies after grouping, unlike WHERE.
- Watch for LEFT JOIN followed by a WHERE on the joined table, which quietly turns it back into an inner join.
Working with the results rather than the query? CSV to JSON turns an exported result set into JSON, and the JSON Formatter makes an API response readable.
Frequently asked questions
Which databases does it understand?
Standard SQL plus PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery, Snowflake, Redshift, Spark, Hive, DuckDB, ClickHouse, Db2, Trino and N1QL. Pick yours so dialect-specific syntax is laid out correctly rather than treated as an error.
Does it change what my query does?
No. Only whitespace, line breaks and the case of keywords change. Table and column names, string values and comments are left exactly as written, so the query still runs the same way.
Why does it say my query could not be read?
Usually an unclosed bracket or quote, a missing comma, or syntax belonging to a different database. Try the dialect your query was written for; a query that is fine in BigQuery can be invalid as standard SQL.
Why does the one-line option remove my comments?
A comment starting with -- runs to the end of the line, so on a single line it would hide the rest of the query. Tick "Keep comments" and they are rewritten as /* … */ instead, which is safe on one line.
Is my query sent anywhere?
No. It is formatted inside your browser, so queries containing table names, customer data or credentials never leave your device.
Last updated