SQL Formatter
Format and beautify SQL queries for various dialects.
Input SQL
Formatted SQL
SELECT * FROM users WHERE id = 1
About SQL formatting
SQL becomes unreadable surprisingly quickly. A single query that started as SELECT id FROM users can grow into a hundred-line CTE with three nested joins, a window function, and a subquery used as a derived table. A formatter restores sanity by splitting clauses onto their own lines, aligning column lists, and indenting join conditions consistently. The point is not pretty output for its own sake — it is making bugs visible during code review.
This formatter understands the dialects of PostgreSQL, MySQL, SQLite, MS SQL Server, BigQuery, and Snowflake. Pick the dialect that matches your database to get the right keyword set and reserved-word handling. As with everything else on the site, the query runs through a parser inside your browser — your SQL is never sent to a server.
How to use
- Paste your SQL query into the input.
- Pick the dialect (Postgres, MySQL, SQLite, MS SQL, BigQuery, Snowflake).
- Choose an indentation style — uppercase keywords with two-space indent is the default.
- Copy the formatted output back into your editor.
Common use cases
- Cleaning up auto-generated ORM SQL before posting it to a code review.
- Reformatting a one-line query lifted from a log file.
- Producing consistently-styled migrations across a codebase.
- Teaching SQL to juniors with readable, hand-styled examples.
Frequently asked questions
Does the formatter execute my query?
Why is keyword case mismatched in the output?
Can it handle multi-statement scripts?
Advertisement