How to Format SQL
SQL pulled out of application code or a query log usually arrives as one enormous line, and a query that long is effectively unreviewable — you can't see where the joins are, which conditions belong to the WHERE clause, or how many columns are being selected. Paste it here and it's restructured around the query's own grammar: a line break before every major clause, each selected column and each AND or OR condition on its own indented line, so the shape of the query becomes obvious at a glance. Multi-word constructs are handled carefully, so LEFT JOIN and LEFT OUTER JOIN stay together on one line instead of being split the way naive formatters do. Keyword uppercasing is on by default, which makes the SQL structure visually distinct from your table and column names, though you can turn it off if your team writes lowercase. Choose two or four space indentation to match your style guide, and switch to minify when you need the query collapsed back to a single compact line for embedding in code. Everything runs in your browser, so queries containing real table names and business logic never leave your machine.
Paste your SQL
Drop in a one-line query or messy formatted SQL.
Choose the style
Set the indent, toggle uppercase keywords, or switch to minify.
Copy or download
Grab the clean query or save it as a .sql file.
Why Formatting Matters
Reviewability
A one-line query hides bugs. Putting each clause and condition on its own line makes a missing join condition or an accidental cartesian product visible immediately, before it reaches production.
Cleaner diffs
When each column sits on its own line, adding one column produces a one-line diff instead of rewriting an entire line — which makes code review far easier and version history more useful.
Common Use Cases
Read a logged query
Turn a one-line query from a slow query log into something readable.
Code review
Format SQL before review so reviewers can see the structure.
Debug a join
Put each join on its own line to spot a missing condition.
Clean up ORM output
Beautify the SQL your ORM actually generated.
Standardise a team style
Apply consistent uppercase keywords and indentation across a codebase.
Documentation
Present readable example queries in docs and runbooks.
Embed in code
Minify a query back to one line for a string literal.
Migration scripts
Format DDL statements before committing them.
Tips & Best Practices
Uppercase keywords, lowercase identifiers
The contrast makes query structure jump out from your table and column names.
One column per line
It keeps diffs small when columns are added or removed, which reviewers appreciate.
Format before committing
Consistent formatting in version control means diffs show real changes, not whitespace churn.
Keep the minified copy out of source
Store the readable version and minify only where a single-line string is required.
Watch for missing join conditions
Once each join is on its own line, an ON clause that isn't there becomes obvious.
Review before running
Formatting changes only whitespace and keyword case, but always sanity-check generated SQL before executing it.
Troubleshooting
A word inside a string got uppercased
Keyword casing is applied by word match, so a keyword appearing inside a quoted literal can be affected. Turn off uppercase for such queries.
My subquery isn't indented deeply
Formatting is clause-based rather than a full parse, so nested subqueries are broken at their clauses but not extra-indented.
Commas inside a function split lines
Every comma starts a new line by design. Use minify if you need function arguments kept together.
Does it change my query's meaning?
No. Only whitespace and keyword case change; the SQL itself is untouched. Always review before running regardless.
Frequently Asked Questions
How do I format SQL for free?
Paste your query above and it's beautified instantly with clause breaks and indentation. Copy or download it — free, no signup.
Does it uppercase keywords?
Yes, by default. You can turn it off if your team writes SQL in lowercase.
Can it minify SQL?
Yes. Minify mode collapses the query to a single compact line for embedding in code.
Does it handle LEFT JOIN correctly?
Yes. Multi-word constructs like LEFT JOIN and LEFT OUTER JOIN are kept intact on one line.
Which SQL dialects work?
The formatter is dialect-agnostic and works with MySQL, PostgreSQL, SQLite, SQL Server and others.
Can I choose the indentation?
Yes. Two or four spaces, whichever matches your style guide.
Does it change my query's behaviour?
No. Only whitespace and keyword case are altered — the SQL logic is untouched.
Does it validate my SQL?
No. It formats rather than parses, so a syntax error will still be formatted. Your database is the validator.
Are my queries sent to a server?
No. Everything runs in your browser, so queries with real table names never leave your device.
Can it format multiple statements?
Yes. Statements separated by semicolons are formatted, and the count is shown above the output.
Does it handle subqueries?
Subqueries are broken at their clauses. Formatting is clause-based, so they aren't given extra nesting indentation.
Why did each column go on its own line?
It keeps diffs minimal when columns change, which makes code review much easier.
Can I download the result?
Yes. Save the output as a .sql file, or copy it to your clipboard.
Does it work with DDL statements?
Yes. CREATE TABLE, ALTER TABLE and DROP TABLE statements are recognised and broken onto their own lines.
Will it break my string literals?
Whitespace inside quoted strings is preserved, though keyword casing can affect keyword-like words inside literals — turn uppercase off if that matters.
Does it work offline?
Once the page has loaded it runs entirely in your browser, so it keeps working without a connection.
Does it work on phones?
Yes, in any modern browser on Windows, Mac, Android or iPhone with nothing to install.
Is this tool really free?
Completely free, forever — no account, no ads and no premium wall.
100% free · No signup · Processed in your browser · Data never sent
Last updated: August 2026 · FlipMyFormat SQL Formatter
Written and maintained by the FlipMyFormat team · Runs entirely in your browser