SQL Formatter
About this tool
A SQL formatter rewrites a query with consistent indentation, capitalised keywords, and one clause per line so a long SELECT is actually readable. It also offers a minify mode that strips line breaks for embedding queries inside application code or environment variables. Useful for any developer who has stared at a 50-line query someone wrote on a single line.
How to use
- Paste the SQL query into the input panel.
- Click Format to render an indented, keyword-uppercased version on the right.
- Use Minify to collapse the formatted query into a single line for embedding.
- Copy the result into your IDE, ORM raw query, BI tool, or migration file.
- Iterate until the query reads naturally — formatting helps catch missing JOIN conditions and stray commas.
Common use cases
- Cleaning up a complex JOIN before pasting it into a code review.
- Formatting an ORM-generated query you copied from a log for debugging.
- Preparing a migration script for a Pull Request that follows team style.
- Minifying a query for embedding inside an application config string.
- Comparing two slightly different queries with a diff tool after formatting both.
- Sharing a readable query in documentation or a Slack thread.
Frequently asked questions
Q. Does the formatter validate my SQL?
A. No — it formats syntax structure but does not verify that columns or tables exist or that the query runs. Use a database client or linter for validation.
Q. Will formatting work for non-standard SQL dialects?
A. Mostly. Common keywords across PostgreSQL, MySQL, SQLite, and MSSQL are recognised. Vendor-specific syntax (PIVOT, MERGE) may format with awkward indentation.
Q. Why does my formatter break a CTE in the wrong place?
A. CTEs (WITH clauses) and subqueries are tricky. If the result looks off, hand-tweak after formatting — it is still faster than starting from scratch.
Q. Should I commit formatted SQL to my repo?
A. Yes — consistent SQL formatting in migrations and stored procedures pays off in code review, just like JS/Python formatting.